我在recyclerView中遇到问题,它没有显示可绘制资源中的图像。
我已经将imageResource与其他text和audioResource存储在数据类中,然后使用适配器填充recyclerView。一切正常,如正确显示文本,播放音频,仅图像视图未显示图像,而是显示紫色框。
这是数据类
@Parcelize
data class Word (
// English Translation of word
var englishTranslation: String,
// French Translation of word
var frenchTranslation: String,
// Image resource for corresponding image to the word
var imageResourceId: Int,
// Audio resource for the pronunciation of the word
var audioResourceId: Int,
// String for description of image
var imageContentDescription: String,
// String for description of audio
var audioResourceContentDescription: String): Parcelable
这是实际的列表数据
private val fruits: MutableList<Word> = mutableListOf(
Word("Apple", "Pomme",
R.drawable.ic_image_apple, R.raw.des_fruits, "Image of the apple",
"pronunciation of the audio"),
Word("Orange", "Orange",
R.drawable.ic_image_apple, R.raw.des_fruits, "image of the Orange",
"Plays the pronunciation audio"),
Word("Strawberry", "Fraise",
R.drawable.ic_image_apple, R.raw.des_fruits, "image of the Strawberry",
"Plays the pronunciation audio")
)
及以下是recyclerView项目布局中imageView的xml代码
<ImageView
android:id="@+id/word_image"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="@dimen/spacing_large"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:contentDescription="@{word.imageContentDescription}"
android:src="@{word.imageResourceId}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/ic_image_apple" />
答案 0 :(得分:0)
问题已经解决,我使用了Kotlin的Binding适配器,就解决了问题