简体   繁体   English

Android可绘制形状角

[英]Android drawable Shape corner

I have a question about the radius value inside the corners tag, what is this radius means actually? 我有一个关于corners标签内的半径值的问题,这个半径实际上意味着什么? is there a center or what? 有中心吗? sample xml: 样本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" />

A picture is worth a thousand words 一张图片胜过千言万语 在此处输入图片说明

I will demo for you. 我将为您演示。 Here is the original rectangle 这是原始矩形

在此处输入图片说明

In your xml file 在您的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>

The result 结果

在此处输入图片说明

4 corners will be rounded by default, if you want round at a specific corner, you can use 4 of these tags: 默认情况下,将对4个角进行四舍五入,如果要在特定的角处四舍五入,则可以使用以下标记中的4个:

  • android:bottomLeftRadius 机器人:bottomLeftRadius
  • android:bottomRightRadius 机器人:bottomRightRadius
  • android:topLeftRadius 机器人:topLeftRadius
  • android:topRightRadius 机器人:topRightRadius

Another example using android:bottomLeftRadius 使用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>

The result 结果

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM