如何显示来自ArrayList <bitmap>(SQLlte)的图像

时间:2019-04-13 14:09:28

标签: java android sqlite android-sqlite android-bitmap

我有一个问题,我无法在我的android studio应用程序的列表中显示数据库中的图像(位图)。

我可以制作一张图片并将其保存(base64)在我的数据库中并检索它。 但是我不知道如何在显示器上显示所有图像。

我尝试使用列表适配器来执行此操作,但这不起作用:/

*

1 个答案:

答案 0 :(得分:0)

这是显示多个视图的快捷方式,具体取决于listData的大小。

首先在LinearLayout中添加your_current_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context=".MainActivity">

</LinearLayout>

在Java类中

   LinearLayout linearLayout = findViewById(R.id.linearLayout);
   ArrayList<Bitmap> listData = new ArrayList<>();

    for (Bitmap a : listData) {
        ImageView image = new ImageView(this);
        image.setLayoutParams(new android.view.ViewGroup.LayoutParams(80, 60));
        image.setMaxHeight(20);
        image.setMaxWidth(20);
        image.setImageBitmap(a);
        linearLayout.addView(image);
      }

下面是我的输出(假设listData中有5张图像)

enter image description here