我正在尝试使用以下代码显示来自sdcard
和drawable
内gridview
的图片。但它不起作用。由于{Galaxy Note
,它会崩溃{1}}但在Memory Error
中显示错误的图像,并且还需要很多时间来显示它们。
emulator
适配器类
DisplayImageOptions options = new DisplayImageOptions.Builder()
.cacheInMemory().cacheOnDisc()
.bitmapConfig(Bitmap.Config.RGB_565).build();
更新:我在gridview中有大约30张图片,一开始它只是在整个地方显示第一张图片,大约需要1分钟才能正确显示所有图片。
logcat的
public class GridAdapter extends BaseAdapter {
public GridAdapter(Context ctx) {
// TODO Auto-generated constructor stub
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(ctx));
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mImages.size();
}
@Override
public Object getItem(int pos) {
// TODO Auto-generated method stub
return mImages.get(pos);
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
public class ViewHolder {
ImageView image;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = getLayoutInflater().inflate(R.layout.grid_image,
parent, false);
holder.image = (ImageView) convertView
.findViewById(R.id.gridImage);
holder.image.setLayoutParams(new LinearLayout.LayoutParams(
width / 2, width / 2));
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (mImages.get(position).getImageSource().equals("sdcard")) {
imageLoader.displayImage(mImages.get(position).getImages(),
holder.image,options);
} else {
String url = "drawable://"
+ Integer.parseInt(mImages.get(position).getImages());
imageLoader.displayImage(url, holder.image,options);
}
return convertView;
}
}