【发布时间】:2017-05-01 20:39:28
【问题描述】:
我从 SQLiteDatabase 获取字节数组并将它们转换为位图,然后将它们添加到图像视图中。我想将图像打印为垂直滚动的图像视图列表。但是,当我尝试添加视图时,它只会打印添加到 LinearLayout 的第一个图像,而不是其余的。
在 onCreate() 中
root = (LinearLayout) findViewById(R.id.photoFeedLayout);
布局
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/photoFeedLayout"
tools:context="com1032.cw2.ms01288.ms01288_assignment2.PhotoFeed">
</LinearLayout>
在我的 PhotoFeed.java 中。
public void run() {
do {
byte[] imData = images.getBlob(images.getColumnIndex("IMAGEDATA"));
Bitmap bm = BitmapFactory.decodeByteArray(imData, 0, imData.length);
LinearLayout.LayoutParams imParams =
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
ImageView iv = (ImageView) new ImageView(getApplicationContext());
iv.setImageBitmap(bm);
root.addView(iv,imParams);
} while (images.moveToNext());
}
有没有更好的方法通过将所有 ImageView 动态添加到根布局来垂直打印它们?
【问题讨论】:
-
从 SQLiteDatabase 获取数组图像的列表视图,以便垂直显示
标签: android sqlite android-layout imageview