美文网首页
Android Shape设置任意个数圆角

Android Shape设置任意个数圆角

作者: YXWKY | 来源:发表于2019-12-18 10:29 被阅读0次

Android Resource中有个shape类型得xml可以设置控件得形状,shape文件定义在drawable目录中,且shape标签必须为root element.官方推荐得标准写法为:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape=["rectangle" | "oval" | "line" | "ring"] >
<corners
        android:radius="integer"
        android:topLeftRadius="integer"
        android:topRightRadius="integer"
        android:bottomLeftRadius="integer"
        android:bottomRightRadius="integer" />
    <gradient
        android:angle="integer"
        android:centerX="float"
        android:centerY="float"
        android:centerColor="integer"
        android:endColor="color"
        android:gradientRadius="integer"
        android:startColor="color"
        android:type=["linear" | "radial" | "sweep"]
        android:useLevel=["true" | "false"] />
    <padding
        android:left="integer"
        android:top="integer"
        android:right="integer"
        android:bottom="integer" />
    <size
        android:width="integer"
        android:height="integer" />
    <solid
        android:color="color" />
    <stroke
        android:width="integer"
        android:color="color"
        android:dashWidth="integer"
        android:dashGap="integer" />
</shape>

值得注意的是,在设置corners的时候,如果想要指定部分圆角,需要将所有的topLeftRadius,topRightRadius,bottomLeftRadius,bottomRightRadius放在一个corners里面,如果每个都放在一个corners里面,最下面的将覆盖最上面的。且:对于指定部分的圆角,官方文档上有说明,需要设置一个radius,并且值需要大于1,其它的如果想设置圆角的地方可以直接写自己想要的值,不想设置圆角的地方则设置为0dp,但是实际测试中发现,不需要设置radius也可以,(可能是测试的手机的api不对)。

Note: Every corner must (initially) be provided a corner radius greater than 1, or else no corners are rounded. If you want specific corners to not be rounded, a work-around is to use android:radius to set a default corner radius greater than 1, but then override each and every corner with the values you really want, providing zero ("0dp") where you don't want rounded corners.

所以,在写shape的时候,需要注意的是将所有的圆角设置在一个corners里面,否则会被覆盖!

相关文章

网友评论

      本文标题:Android Shape设置任意个数圆角

      本文链接:https://www.haomeiwen.com/subject/djvynctx.html