【问题标题】:Image Not Showing In RecyclerView图像未显示在 RecyclerView 中
【发布时间】:2020-12-09 07:40:00
【问题描述】:

我正在开发包含房间数据库以存储 **imagespath** 和该图像的内容的 Android 应用程序。我正在检索该图像路径并从该路径获取图像并在 recyclerview 中显示该图像。我面临的问题是,如果图像尺寸更大,那么如果图像尺寸更大或在 QR 位图中包含更多数据,则不显示图像。

我无法理解问题实际上是什么......

就像我添加了这张图片

如果图像尺寸较大,则图像不显示,我在 Imageview 中看到空白。

我的自定义适配器布局看起来像

 <androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/constmainscan"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/edittextbackground"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.64"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    >

    <ImageView
        android:id="@+id/imgrecyclerviewscan"
        android:layout_width="@dimen/_90sdp"
        android:layout_height="@dimen/_90sdp"
        android:layout_margin="@dimen/_10sdp"
        android:layout_marginStart="@dimen/_10sdp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/txt_detailscan"
        />

    <TextView
        android:id="@+id/txt_detailscan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/_10sdp"
        android:fontFamily="@font/poppins_light"
        android:text="@string/email"
        android:textColor="@color/textcolorblack"
        android:textSize="@dimen/_14sdp"
        android:textStyle="bold"
        app:layout_constraintStart_toEndOf="@id/imgrecyclerviewscan"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/img_contentlogoscan"
        app:layout_constraintVertical_chainStyle="packed"
        android:ellipsize="end"
        android:maxLines="1"
        android:maxLength="20"
        />

    <TextView
        android:id="@+id/txt_contentdetailscan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/_10sdp"
        android:fontFamily="@font/poppins_light"
        android:text="@string/email"
        android:textColor="@color/textcolor"
        android:textSize="@dimen/_10sdp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="@+id/img_contentlogoscan"
        app:layout_constraintStart_toEndOf="@+id/img_contentlogoscan"
        app:layout_constraintTop_toTopOf="@+id/img_contentlogoscan"
        android:maxLength="20"
        />

    <ImageView
        android:id="@+id/img_contentlogoscan"
        android:layout_width="22dp"
        android:layout_height="20dp"
        android:src="@drawable/ic_clipboard_ic"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/txt_contentdetailscan"
        app:layout_constraintStart_toEndOf="@+id/imgrecyclerviewscan"
        app:layout_constraintTop_toBottomOf="@+id/txt_detailscan"
        app:layout_constraintVertical_chainStyle="packed"
        android:layout_marginStart="@dimen/_10sdp"
        android:layout_marginTop="@dimen/_5sdp"

        />

    <ImageView
        android:layout_width="@dimen/_20sdp"
        android:layout_height="@dimen/_20sdp"
        android:id="@+id/btn_deleteqrscan"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:src="@drawable/ic_option_dots"
        android:layout_marginEnd="@dimen/_10sdp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

我从这里获取图像并将其设置为 ImageBitmap

override fun onBindViewHolder(holder: ItemHolder, position: Int) {

    val toDoEntityDataScanned: TodoEntityScanned = arrayList.get(position)
    val path = ":/storage/emulated/0/Maximus/QRScanned/"
    val filename = path.substring(path.lastIndexOf("/") + 1)

    val image = File(toDoEntityDataScanned.imagesPathDatascanned, filename)
    val bmOptions = BitmapFactory.Options()
    var bitmap = BitmapFactory.decodeFile(image.absolutePath, bmOptions)

    holder.itemView.setOnClickListener{
        cellClickListenerScanned.onCellClickListenerScanned(arrayList[position])
    }

    holder.itemView.btn_deleteqrscan.setOnClickListener{
        cellClickListenerScanned.oncellDeleteListenerScanned(arrayList[position])
        arrayList.removeAt(position)
        notifyItemRemoved(position)
    }

    holder.images.setImageBitmap(bitmap)
    holder.logodetail.text = toDoEntityDataScanned.texttypedatascanned
    holder.contentdetail.text = toDoEntityDataScanned.qrcreatedtextdatascanned
    if (Utils.isURLCheck(holder.contentdetail.text as String)){
        Toast.makeText(context,"U"+holder.contentdetail,Toast.LENGTH_LONG).show()
    }
}

我很困惑为什么有时图像没有显示在布局中...

【问题讨论】:

    标签: firebase android-layout kotlin android-recyclerview


    【解决方案1】:

    像这样压缩位图

    bitmap.compress(Bitmap.CompressFormat.JPEG, 75 /质量设置/, outputStream);

    【讨论】:

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