java.lang.Object | |||
↳ | android.graphics.drawable.Drawable | ||
↳ | android.graphics.drawable.DrawableContainer | ||
↳ | android.graphics.drawable.LevelListDrawable |
A resource that manages a number of alternate Drawables, each assigned a maximum numerical value. Setting the level value of the object with setLevel(int) will load the image with the next greater or equal value assigned to its max attribute. A good example use of a LevelListDrawable would be a battery level indicator icon, with different images to indicate the current battery level.
It can be defined in an XML file with the <level-list>
element.
Each Drawable level is defined in a nested <item>
. For example:
<level-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:maxLevel="0" android:drawable="@drawable/ic_wifi_signal_1" /> <item android:maxLevel="1" android:drawable="@drawable/ic_wifi_signal_2" /> <item android:maxLevel="2" android:drawable="@drawable/ic_wifi_signal_3" /> <item android:maxLevel="3" android:drawable="@drawable/ic_wifi_signal_4" /> </level-list>
With this XML saved into the res/drawable/ folder of the project, it can be referenced as the drawable for an ImageView. The default image is the first in the list. It can then be changed to one of the other levels with setImageLevel(int).
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
android:drawable | Reference to a drawable resource to use for the frame. | ||||||||||
android:maxLevel | The maximum level allowed for this item. | ||||||||||
android:minLevel | The minimum level allowed for this item. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Make this drawable mutable.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Override this in your subclass to change appearance if you vary based
on level.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class android.graphics.drawable.DrawableContainer
| |||||||||||
From class android.graphics.drawable.Drawable
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface android.graphics.drawable.Drawable.Callback
|
Reference to a drawable resource to use for the frame. If not given, the drawable must be defined by the first child tag.
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
This corresponds to the global attribute resource symbol drawable.
The maximum level allowed for this item.
Must be an integer value, such as "100
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute resource symbol maxLevel.
The minimum level allowed for this item.
Must be an integer value, such as "100
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute resource symbol minLevel.
Make this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification. Calling this method on a mutable Drawable will have no effect.
Override this in your subclass to change appearance if you vary based on level.