Android开发,使用背景图(xml drawable)为view 设置边框

Android 开发中,遇到需要设置边框的情景,使用背景图来实现,代码如下:

 

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 连框颜色值 -->
    <item>
        <shape>
            <solid android:color="#CCCCCC" />
        </shape>
    </item>
    <!-- 主体背景颜色值 -->
    <item
        android:bottom="1dp"
        android:left="1dp"
        android:right="1dp"
        android:top="1dp">

        <!-- 边框里面背景颜色 白色 -->
        <shape>
            <solid android:color="#ffffff" />
        </shape>
    </item>

</layer-list>

在这里,根据你得实际需要调整下面的部分,控制显示上下左右边框。

     android:bottom="1dp"
        android:left="1dp"
        android:right="1dp"
        android:top="1dp"

posted on 2015-04-14 18:51  张云飞VIR  阅读(829)  评论(0编辑  收藏  举报