Drawable资源之LevelListDrawable资源

A Drawable that manages a number of alternate Drawables, each assigned a maximum numerical value. Setting the level value of the drawable with setLevel() loads the drawable resource in the level list that has aandroid:maxLevel value greater than or equal to the value passed to the method.

file location:
res/drawable/filename.xml
The filename is used as the resource ID.
compiled resource datatype:
Resource pointer to a   LevelListDrawable.
resource reference:
In Java:   R.drawable.filename
In XML:   @[package:]drawable/filename
syntax:
<?xml version="1.0" encoding="utf-8"?>
<level-list
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="@drawable/drawable_resource"
        android:maxLevel="integer"
        android:minLevel="integer" />
</level-list>
 
elements:
<level-list>
This must be the root element. Contains one or more   <item>  elements.

attributes:

xmlns:android
String.   Required.  Defines the XML namespace, which must be "http://schemas.android.com/apk/res/android".
<item>
Defines a drawable to use at a certain level.

attributes:

android:drawable
Drawable resource.   Required. Reference to a drawable resource to be inset.
android:maxLevel
Integer. The maximum level allowed for this item.
android:minLevel
Integer. The minimum level allowed for this item.
example:

 

<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="@drawable/status_off"
        android:maxLevel="0" />
    <item
        android:drawable="@drawable/status_on"
        android:maxLevel="1" />
</level-list>

 

Once this is applied to a View, the level can be changed with setLevel() or setImageLevel().

你可能感兴趣的:(drawable)