创建圆形
Create a rounded shape
我想通过xml创建如下图所示的形状。找了很多让边角变圆滑但没能变圆!
试试这样:
在可绘制文件夹中创建一个 android xml,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
<solid android:color="#96000000" />
<padding
android:bottom="1dp"
android:left="5dp"
android:right="5dp"
android:top="1dp" />
</shape>
为了补充@NoName 的答案,要获得圆形效果,形状的高度必须等于每边的半径。
您在 drawable 文件夹中创建了一个 xml
<?xml version="1.0" encoding="utf-8"?>
<!-- view background color -->
<solid android:color="#19A347" >
</solid>
<!-- If you want to add some padding -->
<padding
android:bottom="2dp"
android:left="5dp"
android:right="5dp"
android:top="2dp" >
</padding>
<!-- Here is the corner radius -->
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" >
</corners>
我想通过xml创建如下图所示的形状。找了很多让边角变圆滑但没能变圆!
试试这样: 在可绘制文件夹中创建一个 android xml,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
<solid android:color="#96000000" />
<padding
android:bottom="1dp"
android:left="5dp"
android:right="5dp"
android:top="1dp" />
</shape>
为了补充@NoName 的答案,要获得圆形效果,形状的高度必须等于每边的半径。
您在 drawable 文件夹中创建了一个 xml
<?xml version="1.0" encoding="utf-8"?>
<!-- view background color -->
<solid android:color="#19A347" >
</solid>
<!-- If you want to add some padding -->
<padding
android:bottom="2dp"
android:left="5dp"
android:right="5dp"
android:top="2dp" >
</padding>
<!-- Here is the corner radius -->
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" >
</corners>