通过Shape实现圆环的绘制,遇到几个问题,刚开始一直绘制不出来,总结一下。
官方文档如下解释android:shape="ring"特有属性
android:innerRadius
Dimension. The radius for the inner part of the ring (the hole in the middle), as a dimension value or dimension resource.
android:innerRadiusRatioFloat. The radius for the inner part of the ring, expressed as a ratio of the ring's width. For instance, ifandroid:innerRadiusRatio="5", then the inner radius equals the ring's width divided by 5. This value is overridden byandroid:innerRadius. Default value is 9.android:thicknessDimension. The thickness of the ring, as a dimension value or dimension resource.android:thicknessRatioFloat. The thickness of the ring, expressed as a ratio of the ring's width. For instance, if android:thicknessRatio="2", then the thickness equals the ring's width divided by 2. This value is overridden by android:innerRadius. Default value is 3.android:useLevelBoolean. "true" if this is used as a
1. uselevel 属性默认是true,值为true意味着这是一个levelListDrawable
一个LeveListDrawable管理着一组交替的drawable资源。LeveListDrawable里面的每一个drawable资源与一个最大数值结合起来,作为LevelListDrawable资源的一项。调用Drawable的setLevel()方法可以加载level-list或代码中定义的某个drawable资源,判断加载某项的方式:level-list中某项的android:maxLevel数值大于或者等于setLevel设置的数值,就会被加载。
这里必须设置为false才会显示。
2.当用户设置android:innerRadius这个属性后,android:innerRadiusRatio 将会被覆盖,android:thicknessRatio同理!
如果不设置android:innerRadius,而设置android:innerRadiusRatio的话,默认值为9,假如设置为5的意思是,内圆环的半径为圆环宽度除以5得到的值。假如该值等于2的话,内圆就将占满整个shape,从而我们将看不到圆环。
3.Stroke标签可设置虚线效果
android:dashWidth——设置虚线效果里实点的长度
android:dashGap——设置虚线效果里空白点的长度
举个例子
android:innerRadius="80dp"
android:shape="ring"
android:thickness="50dp"
android:thicknessRatio="5"
android:useLevel="false">
android:width="400dp"
android:height="400dp" />
android:width="2dp"
android:color="#dcdcdc" />
效果如下 studio显示不知道为啥会多一条横线,实际是没有的。