【发布时间】:2017-01-12 06:44:11
【问题描述】:
我想构建一个图库应用,从我的文件夹中获取照片列表并将其显示在一个页面中。
我降低了图像的分辨率,以便更快地加载图库,但仍然需要很长时间才能加载。
我认为问题在于每次打开应用程序时都会加载每个文件。我该如何解决这个问题?
我在应用中使用了 Gridview。
我的代码:
final GridView[] grid = new GridView[1];
final File[] files = fileOps.getGoodFiles();
//this will return the array of files (images) to be displayed
final CustomGrid adapter = new CustomGrid(GeoGallery.this,files);
grid[0] =(GridView)findViewById(R.id.grid);
grid[0].setAdapter(adapter);
在我的 CustomGridView 中:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid;
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
grid = inflater.inflate(R.layout.grid_single, null);
ImageView imageView = (ImageView)grid.findViewById(R.id.grid_image);
Bitmap bitmap = BitmapFactory.decodeFile(files[position].getPath());
bitmap = Bitmap.createScaledBitmap(bitmap,120,120*bitmap.getHeight()/bitmap.getWidth(),false);
imageView.setImageBitmap(bitmap);
return grid;
}
如何让它加载更快?
【问题讨论】:
标签: android image gallery thumbnails image-gallery