Android ImageButton和FrameLayout中的按钮赢得';t变换z指数

Android ImageButton和FrameLayout中的按钮赢得';t变换z指数,android,android-layout,Android,Android Layout,切换元素顺序时,将按钮置于图像按钮之后,z索引不受影响。我尝试了其他类型的视图,它们根据它们在父视图FrameLayout中的顺序正确放置在彼此的顶部。 我尝试以编程方式使用View.bringToFront()但没有成功 <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:layou

切换元素顺序时,将
按钮
置于
图像按钮
之后,z索引不受影响。我尝试了其他类型的视图,它们根据它们在父视图
FrameLayout
中的顺序正确放置在彼此的顶部。 我尝试以编程方式使用View.bringToFront()但没有成功

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Suzi"
        android:textSize="22sp" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher" />

</FrameLayout>

我试图复制这个问题:它是在棒棒糖+设备上为我复制的,而不是在棒棒糖前复制的。 你能检查一下这个吗

如果情况确实如此,那么解决方案可能是使用
android:translationZ
attribute(从Lollipop开始提供)

比如:

<FrameLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Suzi"
        android:textSize="22sp"
        android:translationZ="1dp"/>

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:translationZ="2dp"/>

</FrameLayout>

事实上,translationZ在棒棒糖制作前是不可用的,这并不重要(属性将被忽略),因为不存在这样的问题


希望有帮助

框架布局中放置两个按钮有什么意义
?按钮没有ID,如何调用bringToFront()?发布代码要点是将一个按钮放在一边,有一些偏移,但在另一个按钮之上。我尝试过bringToFront()的地方,它们有ID,这里的要点是,我认为当更改框架中的顺序时,它们应该更改堆栈位置发布代码,如果没有它,我们可以帮助您。。。也许你用错了bringToFront()或者别的什么,现在我们只能相信你的话了