您的位置:首页 > 移动开发 > Android开发

Android Shape 资源文件

2016-10-09 18:46 441 查看

通过Shape实现圆环的绘制,遇到几个问题,刚开始一直绘制不出来,总结一下。

官方文档如下解释
android:shape="ring"
特有属性android:innerRadiusDimension. The radius for the inner part of the ring (the hole in the middle), as a dimension value or dimensionresource.
android:innerRadiusRatio
Float. The radius for the inner part of the ring, expressed as a ratio of the ring's width. For instance, if
android:innerRadiusRatio="5"
, then the inner radius equals the ring's widthdivided by 5. This value is overridden by
android:innerRadius
. Default value is 9.
android:thickness
Dimension. The thickness of the ring, as a dimension value or dimensionresource.
android:thicknessRatio
Float. 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. Thisvalue is overridden by 
android:innerRadius
. Default value is 3.
android:useLevel
Boolean. "true" if this is used as a 
LevelListDrawable
.This should normally be "false" or your shape may not appear.

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——设置虚线效果里空白点的长度
举个例子
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"android:innerRadius="80dp"android:shape="ring"android:thickness="50dp"android:thicknessRatio="5"android:useLevel="false"><sizeandroid:width="400dp"android:height="400dp" /><strokeandroid:width="2dp"android:color="#dcdcdc" /><solid android:color="#f2354e" /></shape>
效果如下 studio显示不知道为啥会多一条横线,实际是没有的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: