Drawable的使用——LayerDrawable

LayerDrawable对应的xml标签是,他是一种层次化的drawable集合,通过将不同的Drawable放置在不同的层上从而达到一种叠加的效果。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="5dp"/>
            <solid android:color="#0ac39e" />
        </shape>
    </item>
    <item android:bottom="26dp">
    <shape android:shape="rectangle">
    <solid android:color="#ffffff" />
    </shape>
    </item>
    <item
        android:bottom="5dp"
        android:left="10dp"
        android:right="10dp">
        <shape android:shape="rectangle">
            <corners android:radius="10dp"/>
            <solid android:color="#ffffff" />
        </shape>
    </item>
</layer-list>

item中可以找现有的drawable资源,也可以自定义资源,如上面xml中用的shape

看下面的效果,将drawable设置为一个textview的背景
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章