【发布时间】:2016-04-12 09:20:39
【问题描述】:
我目前有一个应用程序,可以将应用程序中的图像保存到内部存储以供以后查看。我想拥有应用程序中所有图像的图库。但是,如果我将 7 个或更多图像加载到 gridview 中,应用程序就会开始滞后,并且需要一些时间来加载该活动。
所以我想知道如何优化它。
将图片加载到ArrayList:
final ArrayList<ImageItem> imageItems = new ArrayList<>();
//TypedArray imgs = getResources().obtainTypedArray(R.array.image_ids);
for (int i = 1; i < getApplicationContext().fileList().length; i++) {
String[] names = getApplicationContext().fileList();
Log.d("HIER:", names[i]);
Bitmap b = null;
try{
InputStream is = getApplicationContext().openFileInput(names[i]);
b = BitmapFactory.decodeStream(is);
} catch(Exception e){
e.printStackTrace();
}
//arrayList.add(new ImageItem(Bitmap.createScaledBitmap(b, 100, 100, false), names[i]));
arrayList.add(new ImageItem(b, names[i]));
设置gridview:
gridView = (GridView) findViewById(R.id.gridView);
gridAdapter = new GridViewAdapter(this, R.layout.favorite_item, arrayList);
gridView.setAdapter(gridAdapter);
【问题讨论】:
-
您需要使用 imageLoader 库或 Picasso 库来加载图像。谷歌这些名字,你会找到很多答案
标签: android android-studio gridview