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>



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