InsetDrawable

總結(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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容