Android中圆角矩形背景

四个角都为圆角

在drawable文件夹下新建文件round.xml


<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
     
     
    
    <solid android:color="#70707070" />
    
    
    <stroke
    android:width="1dp"
    android:color="#70707070"/>
    
    <corners
        android:radius="2dp"/> 
shape>

接着在布局文件进行引用就可以了,把这个drawable作为组件的background

android:background="@drawable/round"

部分角为圆角


<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
     
     
    
    <solid android:color="#70707070" />
    
    
    <stroke
    android:width="1dp"
    android:color="#70707070"/>
     
    
    <corners
    	android:radius="2dp"
        android:topLeftRadius="8dp"
        android:topRightRadius="8dp"
        android:bottomRightRadius="0dp"
        android:bottomLeftRadius="0dp"
        />
 
shape>

需要注意的是:
1、在设置圆角时,圆角半径的大小必须大于1,否则是没有圆角效果的
1、如果你想单独设置某几个角是圆角, 你必须首先声明 radius 属性(必须大于1), 然后在其他四个角的属性中设置每个角的实际想要的半径大小, 不想圆角的设置为(“0dp”).

你可能感兴趣的:(Android中圆角矩形背景)