Android开发之shape画圆环的方法

方法一:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadiusRatio="3"
    android:shape="ring"
    android:thicknessRatio="8"
    android:useLevel="false">
    <gradient
        android:centerColor="#ff0000"
        android:endColor="#0ff676"
        android:startColor="#B23AEE"
        android:useLevel="false" />
</shape>

效果图如下:



方法二:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:useLevel="false">
    <stroke
        android:width="2dp"
        android:color="#ff0000" />
    <size
        android:width="20dp"
        android:height="20dp" />
</shape>

效果如下:



方法三:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="100dp"
    android:shape="ring"
    android:thickness="10dp"
    android:useLevel="false">
    <stroke
        android:width="10dp"
        android:color="#ff6652" />
    <!--这里可以看出shape中的android:thickness属性和stoke中的android:width属性的作用,
    android:thickness是圆环的宽度,而android:width是圆环边缘线的宽度。如果设置成一样,
    就会如图1所示,但这个一般不符合UI需求,会发现圆环宽度比较大,其实是android:thickness的2倍。
    这里其实不该用stoke,该用solid指定填充色就OK了。
    而想要图二效果的注意android:width一定要比android:thickness小。-->
</shape>

效果如下:


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值