Android RelativeLayout中的子视图不重叠

Android RelativeLayout中的子视图不重叠,android,android-layout,android-relativelayout,Android,Android Layout,Android Relativelayout,我在Android中设置了以下布局。我希望TextView作为计数器重叠在按钮的右下角 它不是在按钮上重叠,而是在按钮下重叠。它永远不会出现在前景中 我知道我可以使用API 21的Elevation属性,但我希望与早期设备兼容 我希望将文本视图放在按钮之后,以充分实现我想要的功能-无法理解为什么它的行为不符合预期 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:or

我在
Android
中设置了以下布局。我希望
TextView
作为计数器重叠在按钮的右下角

它不是在按钮上重叠,而是在按钮下重叠。它永远不会出现在前景中

我知道我可以使用API 21的Elevation属性,但我希望与早期设备兼容

我希望将
文本视图
放在
按钮
之后,以充分实现我想要的功能-无法理解为什么它的行为不符合预期

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

    <Button
        android:layout_height="60dp"
        android:layout_width="60dp"
        android:id="@+id/chat_request"
        android:background="@drawable/chatbubble"
        android:duplicateParentState="true"
        android:enabled="false"
        android:layout_alignWithParentIfMissing="false"
        android:focusable="false" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1"
        android:id="@+id/request_counter"
        android:layout_alignParentRight="false"
        android:layout_alignParentEnd="false"
        android:background="@drawable/count_background"
        android:textColor="@color/white"

        android:layout_gravity="bottom|right"
        android:layout_below="@+id/chat_request"
        android:layout_alignRight="@+id/chat_request"
        android:layout_marginTop="-15dp"
        android:duplicateParentState="true"
         />

</RelativeLayout>

试试这个:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/chatbubble">

<Button
    android:layout_height="60dp"
    android:layout_width="60dp"
    android:id="@+id/chat_request"
    android:duplicateParentState="true"
    android:enabled="false"
    android:layout_alignWithParentIfMissing="false"
    android:focusable="false"
    android:background="@color/transparent"/>



<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="1"
    android:id="@+id/request_counter"
    android:layout_alignParentRight="false"
    android:layout_alignParentEnd="false"
    android:background="@drawable/count_background"
    android:textColor="@color/white"

    android:layout_gravity="bottom|right"
    android:layout_below="@+id/chat_request"
    android:layout_alignRight="@+id/chat_request"
    android:layout_marginTop="-15dp"
    android:duplicateParentState="true"
    />

 </RelativeLayout>

这是因为我使用了一个按钮元素。无论按钮在相对位置上的位置如何,它始终取代任何其他元素


但是,当我将该元素更改为ImageButton时,它采用了我预期的行为:它与布局中以前的UI元素重叠,如果它位于XML中这些元素的下面。

实际上,这里的解决方案是使用ImageButton-按钮对象保持在顶部。感谢您提供的信息:)不知道为什么这个问题被否决了-如果这样做的人能够给出反馈,这将对下次非常有帮助!谢谢