android:为什么文本视图不会叠加在 FrameLayout 中的按钮上

Joh*_*ard 2 android android-framelayout

几乎每篇关于分层小部件主题的文章都指向 FrameLayouts,它应该根据 XML 中的出现顺序进行堆叠。为了测试,我在xml中放了一个按钮和一个TextView,希望能看到TextView与按钮重叠。按钮是放在 textview 之前还是之后都没有关系,按钮总是在顶部。谁能看到我做错了什么?

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.jdot.testloadingfragments.MainActivity">

    <Button
        android:id="@+id/btn_test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:text="        "
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="----------------------------------------------------------"/>


</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

Isa*_*aac 5

添加elevation到 textView 将使其显示在Button

例如

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.jdot.testloadingfragments.MainActivity">

    <Button
        android:id="@+id/btn_test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:text="        "/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:elevation="2dp"
        android:text="----------------------------------------------------------"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

更多信息:为什么框架布局没有正确绘制 z 索引?