为什么FrameLayout没有在我的布局中正确设置Z顺序?

Dra*_*ško 2 android android-layout android-framelayout

我有以下布局(这里提供了更简单的设计):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main">
    <FrameLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hey, badge!"
            android:layout_margin="10dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="AAAAA"
            android:layout_margin="10dp"
            android:textSize="12sp"
            android:background="#ff00ff"
            android:padding="10dp"
            android:layout_gravity="top|end"
            />
    </FrameLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我希望将TextView设置为文本"AAAA"以充当Button的徽章,即将其放置在其右上角的按钮上,但事实并非如此.

相反,当我在带有Lollipop的HTC One M7或带有Lollipop的Genymotion Nexus 6上尝试此代码时,屏幕看起来像这样:

视图截图严重放置

当我使用KitKat在Genymotion Nexus 5上尝试相同的代码时,一切看起来都符合预期,即第一个视图(按钮)显示在徽章(textview)下面

有没有人知道这里有什么问题?

谢谢,Deveti

Tam*_*seh 5

海拔导致此问题.它在Lollipop中引入并负责z-ordering.将布局复制到按钮layout-v21并设置android:elevation="0dp".