Android可绘制形状角

时间:2018-08-24 09:15:18

标签: android android-drawable shape

我有一个关于Corners标签内的半径值的问题, 这个半径实际上意味着什么?有中心吗? 样本xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<corners
    android:radius="20dp" />

<solid
    android:color="@android:color/transparent" />

<stroke
    android:color="#FFFFFF"
    android:width="2dp" />

<size
    android:width="165dp"
    android:height="40dp" />

1 个答案:

答案 0 :(得分:2)

  

一张图片值一千字   enter image description here

我将为您演示。这是原始矩形

enter image description here

在您的xml文件中

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="45dp" />

    <solid android:color="#22B14C" />
</shape>

结果

enter image description here

默认情况下,将对4个角进行四舍五入,如果要在特定的角处四舍五入,可以使用以下标记中的4个:

  • android:bottomLeftRadius
  • android:bottomRightRadius
  • android:topLeftRadius
  • android:topRightRadius

另一个使用android:bottomLeftRadius

的示例
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:bottomLeftRadius="45dp"/>

    <solid android:color="#22B14C" />
</shape>

结果

enter image description here

相关问题