
總結(jié).png
其他Draw文章參考:
Android中Drawable整體介紹
前言
談可以將其他Drawable內(nèi)嵌到自己當(dāng)中。 當(dāng)View需要一個(gè)小于View的實(shí)際邊界的背景時(shí)使用。
對(duì)應(yīng)于<inset>標(biāo)簽,它可以將其他Drawable內(nèi)嵌到自己中,并且可以留出一定的間距。當(dāng)view希望自己的背景比自己的實(shí)際區(qū)域小的時(shí)候,可以采用。
語(yǔ)法
<?xml version="1.0" encoding="utf-8"?>
<inset
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/drawable_resource"
android:insetTop="dimension"
android:insetRight="dimension"
android:insetBottom="dimension"
android:insetLeft="dimension" />
<inset>
定義插入可繪制對(duì)象。這必須是根元素。
屬性:
xmlns:android
字符串。必備。定義 XML 命名空間,其必須是 "http://schemas.android.com/apk/res/android"。
android:drawable
可繪制對(duì)象資源。必備。引用要插入的可繪制對(duì)象資源。
android:insetTop
尺寸。頂部插入,表示為尺寸值或尺寸資源
android:insetRight
尺寸。右邊插入,表示為尺寸值或尺寸資源
android:insetBottom
尺寸。底部插入,表示為尺寸值或尺寸資源
android:insetLeft
尺寸。左邊插入,表示為尺寸值或尺寸資源
實(shí)例
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/red_drawable"
android:insetTop="10dp"
android:insetRight="10dp"
>
</inset>
XML中:這里放兩個(gè)TextView進(jìn)行對(duì)比
<TextView
android:layout_width="match_parent"
android:layout_height="49dp"
android:background="#fdff"/>
<TextView
android:layout_width="match_parent"
android:layout_height="49dp"
android:background="@drawable/inset_darawable"/>
效果圖:

image.png