Levellist 显示时不像scale list 或 layout list那样要用代码设置一下,可以直接显示。改变level时才用代码。
1.res:level_list.xml
<?xml version="1.0" encoding="utf-8"?> <level-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/level_list_1" android:maxLevel="0" />
<item android:drawable="@drawable/level_list_2" android:maxLevel="1" />
<item android:drawable="@drawable/level_list_3" android:maxLevel="2" />
<item android:drawable="@drawable/level_list_4" android:maxLevel="3" />
</level-list>
2.使用
<ImageView
android:id="@+id/level_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/level_list" />
3.改level
case R.id.level_list:
level = levelListdrawable.getLevel();
levelListdrawable.setLevel(++level);
level %= ;
break;