Android中Layer-list的使用 为控件添加边线


使用layer-list为控件添加边框

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 外部边框-->
    <item>
        <shape>
            <!--外部边框颜色-->
            <solid android:color="#ff0000" />
            <!--外部边框范围,为0dp则是外部无边框,控制此属性来设置边框-->
            <padding
                android:bottom="10dp"
                android:left="0dp"
                android:right="0dp"
                android:top="10dp" />
            <!--设置外部边框圆角,可选-->
            <corners android:radius="5dp"/>
        </shape>
    </item>
    <!-- 主体背景 -->
    <item>
        <shape>
            <!--主体背景颜色-->
            <solid android:color="#00ff00" />
            <!--主体背景边框,可选-->
            <stroke android:color="0000ff"
                android:width="5dp"/>
            <!--主体边框圆角,从主体边框算起,在圆角大的情况下,主体背景也会随着主体边框有了圆角,可选-->
            <corners android:radius="10dp"/>
        </shape>
        <!--可以加padding属性,是该组件内容距该组件主体背景边框的填充区域的范围,一般不用-->
        <padding
            android:bottom="20dp"
            android:left="0dp"
            android:right="20dp"
            android:top="10dp" />
    </item>
</layer-list>



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