I have a 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. Here is xml Layout:
<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.
Exactly as I thought your content indicators are incorrect (unless you wanna introduce such a content padding with your 9-patch). Try this instead:
Right and bottom guides, determine which part (or how much) of your drawable
should be occupied by your content. You've set this region to really small space, and set a fixed height of your 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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.