簡體   English   中英

RelativeLayout背景可繪制重疊內容

[英]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補丁引入這樣的內容填充)。 試試這個:

9補丁

右側和底部指南,確定哪些部分(或多少),您的drawable應該由你的內容所占據。 您已將此區域設置為非常小的空間,並設置Layout的固定高度。 換句話說:9-patch強制你的Layout讓它的孩子只占據你視圖的一小部分區域(受限於你沒有讓你的Layout拉伸)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM