一.实现效果
二.步骤
1.新建drawable资源文件
首先在drawable文件下新建一个radius_border.xml文件,在创建之前先来了解下各个属性的作用
- solid : 背景填充
- corners :圆角 (可单独设置圆角)
- stroke :边框(可设置边框宽度和颜色)
- padding :内边距
- gradient :渐变色(背景)
- size :大小
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<!-- 圆角 <corners android:radius="15dp"/>-->
<corners
android:topRightRadius="15dp"
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"/>
<stroke android:width="1dp" android:color="#eeeeee"/>
</shape>
2. 使用
可以通过设置backgroud="@drawable/radius_border"来使用,具体如下所示:
<LinearLayout
android:background="@drawable/radius_border"
android:gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="200dp">
<TextView
android:text="圆角边框"
android:textColor="#ffff0000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>