关卡列表不适用于 ImageView - Android
Level List Not working for ImageView - Android
我在 android 中练习级别列表并创建了一个小应用程序,但是当我尝试更改级别时,图像视图中的图像没有改变...
默认显示 level_list.xml
中的第一张图片
activity_main.xml
<ImageView
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/level_list" />
level_list.xml
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="1" android:drawable="@drawable/logo"/>
<item android:maxLevel="0" android:drawable="@drawable/ruppe_btn1_selected"/>
</level-list>
MainActivity.Kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val imageLevelList = findViewById<ImageView>(R.id.imageButton)
imageLevelList.setImageLevel(0) //tried with 1
}
}
提前致谢
只需更改 level_list.xml
文件中的 android:maxLevel
顺序
只需更改如下顺序即可:
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="0" android:drawable="@drawable/ruppe_btn1_selected"/>
<item android:maxLevel="1" android:drawable="@drawable/logo"/>
</level-list>
我在 android 中练习级别列表并创建了一个小应用程序,但是当我尝试更改级别时,图像视图中的图像没有改变...
默认显示 level_list.xml
activity_main.xml
<ImageView
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/level_list" />
level_list.xml
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="1" android:drawable="@drawable/logo"/>
<item android:maxLevel="0" android:drawable="@drawable/ruppe_btn1_selected"/>
</level-list>
MainActivity.Kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val imageLevelList = findViewById<ImageView>(R.id.imageButton)
imageLevelList.setImageLevel(0) //tried with 1
}
}
提前致谢
只需更改 level_list.xml
文件中的 android:maxLevel
顺序
只需更改如下顺序即可:
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="0" android:drawable="@drawable/ruppe_btn1_selected"/>
<item android:maxLevel="1" android:drawable="@drawable/logo"/>
</level-list>