【发布时间】:2020-04-12 01:01:01
【问题描述】:
我在 recyclerView 中遇到问题,它没有显示来自可绘制资源的图像。
我已将 imageResource 与其他文本和 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" />
【问题讨论】:
标签: android kotlin android-recyclerview android-imageview