Android -purpose of useLevel in shape tag Android -purpose of useLevel in shape tag xml xml

Android -purpose of useLevel in shape tag


It is for ProgressBars. For example this gist uses a ring shape as a progress drawable.

res/drawable/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>

In your layout:

<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"/>

Basically, useLevel makes it so the drawable can be drawn partially. For example there is a method ImageView.setImageLevel() that lets you set a "level," e.g. 25% progress, so the ring drawable would be drawn as a quarter-circle. And ProgressBar.setProgress() does the same thing, updating the "level" of the drawable you've set on the ProgressBar.