RelativeLayout 背景可绘制重叠内容

RelativeLayout background drawable overlap content

我有一个 9 补丁的可绘制对象 (date_time)。我想将此可绘制对象放在相对布局内容的后面,因此所有子视图都应绘制在此图像之上。 这是 xml 布局:

<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="23dp"
            android:layout_below="@id/tv_map_address"
            android:layout_marginTop="11dp"
            android:layout_marginBottom="12dp"
            android:background="@drawable/date_time">

            <ImageView
                android:id="@+id/iv_map_distance"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_centerVertical="true"
                android:src="@drawable/ic_map_distance"/>

            <TextView
                android:id="@+id/tv_map_distance"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/iv_map_distance"
                android:layout_centerVertical="true"
                android:textColor="@color/white"
                android:textSize="11sp"
                android:text="2,7 км"
                fontPath="fonts/Roboto-Medium.ttf"/>

            <ImageView
                android:id="@+id/iv_map_path"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/tv_map_distance"
                android:layout_centerVertical="true"
                android:src="@drawable/ic_map_path"/>

            <TextView
                android:id="@+id/tv_map_path"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/iv_map_path"
                android:layout_centerVertical="true"
                android:textColor="@color/white"
                android:textSize="11sp"
                android:text="3,2 км"
                fontPath="fonts/Roboto-Medium.ttf"/>

        </RelativeLayout>

但是这个背景以某种方式与所有子内容重叠。 这里显示了正在发生的事情。

但是如果我替换

android:background="@drawable/date_time"

android:background="#0000FF"

一切正常,接下来输出:

你能解释一下我做错了什么吗?

更新: 这是我的 9 补丁可绘制对象。

正如我认为您的内容指示器不正确一样(除非您想在 9-patch 中引入这样的内容填充)。试试这个:

右侧和底部指南,确定您的 drawable 的哪一部分(或多少)应该被您的内容占据。您已将此区域设置为非常小 space,并设置了 Layout 的固定高度。换句话说:9-patch 迫使你的 Layout 让它的 children 只占据你视野的一小部分区域(这受到你不让你的 Layout 伸展的限制)。