android给View设置上下左右边框

给View控件设置边框,可以动态设置上下左右.通过布局文件就能搞定


1.在drawable文件夹下新建一个shape_main_list_bg.xml文件

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- This is the main color -->
    <item>
        <shape>
                <!--    边框颜色 -->
            <solid android:color="#00FF00"/>
        </shape>
    </item>
    <!-- 给View的上 左  右设置8dp的边框 -->
    <item android:top="8dp" android:left="8dp" android:right="8dp" >
        <shape>
				<!--     View填充颜色 -->
            <solid android:color="#FFFFFF" />
        </shape>
    </item>

</layer-list>



2.给控件设置背景

    <EditText
        android:padding="20dp"
        android:layout_margin="15dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入Edittext内容"
        android:background="@drawable/shape_main_list_bg"/>


3.效果图如下:

  


推荐下自己创建的android QQ群:202928390 欢迎大家的加入.

  

原文地址:https://www.cnblogs.com/yishaochu/p/5078609.html