android shape xml标签useLevel属性的目的是什么?这与图层列表有关,但无关紧要。 从docs我发现了useLevel标签的结果:
指示可绘制的级别是否会影响绘制渐变的方式。
所以,如果我有以下xml片段:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="15dp"
android:thickness="10dp"
android:useLevel="false">
<solid android:color="#ababf2" />
<size
android:height="50dp"
android:width="50dp" />
</shape>
然后使用useLevel = true,禁用环。戒指出现必定为假。但是这个属性的目的是什么?文档不清楚。
答案 0 :(得分:4)
适用于ProgressBars。例如,this gist使用环形作为可绘制的进度。
RES /抽拉/ github_232_circular.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2.3"
android:shape="ring"
android:thickness="3.8sp"
android:useLevel="true">
<solid android:color="#ff0000" />
</shape>
在你的布局中:
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="top|end"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/github_232_circular"
/>
基本上,useLevel
使得绘图可以部分绘制。例如,有一种方法ImageView.setImageLevel()可让您设置&#34;级别,&#34;例如25%的进度,因此环形绘制将绘制为四分之一圆。 ProgressBar.setProgress()做同样的事情,更新&#34;等级&#34;你在ProgressBar上设置的drawable。