【问题标题】:Drawable image not showing in RecyclerView可绘制图像未在 RecyclerView 中显示
【发布时间】: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


    【解决方案1】:

    问题已经解决了,我使用了 Kotlin 的 Binding 适配器,问题就解决了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-18
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多