[英]RelativeLayout background drawable overlap content
I have a 9-patch drawable(date_time). 我有一个9-patch drawable(date_time)。 And i want to place this drawable behind Relative Layout content, so all child views should be drawn on top of this image. 我想将此drawable放在Relative Layout内容后面,因此所有子视图都应该在此图像的顶部绘制。 Here is xml 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>
But somehow this background overlaps all child content. 但不知何故,这种背景与所有儿童内容重叠。 Here is shown what is happening. 这里显示了正在发生的事情。
But if i replace 但如果我更换
android:background="@drawable/date_time"
to 至
android:background="#0000FF"
Everything is fine and the output is next: 一切都很好,输出是下一个:
Can you explain me what i am doing wrong? 你能解释一下我做错了什么吗?
Update: Here is my 9-patch drawable. 更新:这是我的9-patch drawable。
Exactly as I thought your content indicators are incorrect (unless you wanna introduce such a content padding with your 9-patch). 正如我认为你的内容指标不正确(除非你想用你的9补丁引入这样的内容填充)。 Try this instead: 试试这个:
Right and bottom guides, determine which part (or how much) of your drawable
should be occupied by your content. 右侧和底部指南,确定哪些部分(或多少),您的drawable
应该由你的内容所占据。 You've set this region to really small space, and set a fixed height of your Layout
. 您已将此区域设置为非常小的空间,并设置Layout
的固定高度。 In other words: 9-patch forced your Layout
to let its children occupy only a small, region of your view (which was limited by you not letting your Layout
stretch). 换句话说:9-patch强制你的Layout
让它的孩子只占据你视图的一小部分区域(受限于你没有让你的Layout
拉伸)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.