[英]RelativeLayout background drawable overlap content
我有一个9-patch drawable(date_time)。 我想将此drawable放在Relative Layout内容后面,因此所有子视图都应该在此图像的顶部绘制。 这是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-patch drawable。
正如我认为你的内容指标不正确(除非你想用你的9补丁引入这样的内容填充)。 试试这个:
右侧和底部指南,确定哪些部分(或多少),您的drawable
应该由你的内容所占据。 您已将此区域设置为非常小的空间,并设置Layout
的固定高度。 换句话说:9-patch强制你的Layout
让它的孩子只占据你视图的一小部分区域(受限于你没有让你的Layout
拉伸)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.