最近UI有需求要画个圆环,当然想到用shape,本着copy来代码就能用的原则百度了下,发现好多例子都是这样写的
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="100dp"
android:thickness="10dp"
android:useLevel="false">
<stroke
android:width="10dp"
android:color="#ad7997"
/>
</shape>
这样绘制的也没啥错误的
如上图所示,但是把stroke的width减少点就会如下图:
这里可以看出shape中的android:thickness属性和stoke中的android:width属性的作用,android:thickness是圆环的宽度,而android:width是圆环边缘线的宽度。如果设置成一样,就会如图1所示,但这个一般不符合UI需求,会发现圆环宽度比较大,其实是android:thickness的2倍。这里其实不该用stoke,该用solid指定填充色就OK了。
而想要图二效果的注意android:width一定要比android:thickness小。