简体   繁体   English

recyclerView 不显示图像

[英]recyclerView doesn't display the images

I am trying to show images in recyclerView but it doesn't display the bitmaps.我正在尝试在 recyclerView 中显示图像,但它不显示位图。 I don't know what is wrong.我不知道出了什么问题。

This is my adapter:这是我的适配器:

@Override
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
    final byte[] data = arrayList.get(position).getAsByteArray("byteArray");

    try {
        String tempImagePath = Environment.getExternalStorageDirectory().getPath() + "/AHOORATempImage";
        FileOutputStream fileOutputStream = new FileOutputStream(tempImagePath);
        fileOutputStream.write(data);
        fileOutputStream.flush();
        fileOutputStream.close();

        holder.image.setImageBitmap(BitmapFactory.decodeStream(new FileInputStream(tempImagePath)));

        new File(tempImagePath).delete();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

and This is the xml of my item:这是我的商品的 xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.cardview.widget.CardView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:cardCornerRadius="3dp">
    <ImageView
        android:id="@+id/addContentGalleryImage"
        android:layout_width="300dp"
        android:layout_height="300dp"/>
</androidx.cardview.widget.CardView>

Thanks!谢谢!

you can use Picasso library it's easy to use and very helpful with Url image especially.您可以使用Picasso 库,它易于使用并且对 Url 图像非常有帮助。 here's an example to use in onBindViewHolder这是在onBindViewHolder中使用的示例

Picasso.get()
            //Image url or path
            .load(channelImgUrl.get(position))
            //This line optional if you want a circle Image shape
            .transform(new CropCircleTransformation())
            //Image View
            .into(holder.channelImg);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM