API>20 时,RelativeLayout 最后的 ChildView 看不到

ChildView in the last of RelativeLayout cannot see when API>20

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
>
<Button
    android:text="button"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    />
<TextView
    android:text="right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
     />
</RelativeLayout>

当API>20时,TextView被按钮覆盖,如何解决?如果第一个child是一个TextView,它不会happen.Does它是一个错误android?

试试这个,

    <?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <Button
            android:text="button"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff"
            android:layout_toLeftOf="@+id/tv_right"
            />
        <TextView
            android:id="@+id/tv_right"
            android:text="right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            />
    </RelativeLayout>

您的根布局的高度和宽度为 match_parent 您正在通过 android:layout_height=match_parent

按钮占用完整的 space

并且对于文本视图,您没有使用按钮的引用来放置在布局上相对布局提供了 android:layout_below 属性,您可以将其用于将您的文本视图放在按钮下方

查看下面的示例将为您提供更多详细信息

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <Button
        android:text="button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:background="#ffffff"
        />
    <TextView
        android:text="right"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button"
        android:layout_alignParentRight="true"
        />
</RelativeLayout>

要强调:这不是 android 中的错误android 你没有以正确的方式使用它