LevelListDrawable对应于标签,它同样表示一个Drawable集合,集合中每个Drawable都有一个等级(level)的概念。根据不通的等级,LevelListDrawable会显示对应的Drawable
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/ic_sunny"
android:maxLevel="10"
android:minLevel="0" />
<item
android:drawable="@drawable/ic_night"
android:maxLevel="20"
android:minLevel="11" />
<item
android:drawable="@drawable/ic_cloudy"
android:maxLevel="30"
android:minLevel="21" />
</level-list>
var count = 0
iv_level_list.setOnClickListener {
count++
when (count % 3) {
0 -> iv_level_list.drawable.level = 5
1 -> iv_level_list.drawable.level = 15
2 -> iv_level_list.drawable.level = 25
}
}