我在项目中使用 universalimageloader 来显示许多图片 当我尝试显示图像时,它太慢了,在评论了显示行图像后,它也显示了行,而不是慢 我试过的代码是:
public class GridAdapterMa extends BaseAdapter {
ArrayList<JobItem> objects = new ArrayList<JobItem>();
int size = 0;
private String TAG = GridAdapterMa.class.getSimpleName();
ImageLoader imageLoader;
DisplayImageOptions options;
ImageLoaderConfiguration config;
public GridAdapterMa(ArrayList<JobItem> objects) {
size = objects.size();
this.objects.addAll(objects);
ExceptionHelpers.dLog(TAG, "Constructor");
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.thumb_square)
.showImageForEmptyUri(R.drawable.thumb_square)
.showImageOnFail(R.drawable.thumb_square)
// .cacheInMemory(false)
.cacheOnDisc(true)
.resetViewBeforeLoading(true)
// .delayBeforeLoading(100)
.considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.displayer(new SimpleBitmapDisplayer())
/*.preProcessor(new BitmapProcessor() {
@Override
public Bitmap process(Bitmap bitmap) {
int w = (int) (UIHelpers.width * 0.50);
float r = ((float) bitmap.getHeight() / (float) bitmap.getWidth());
int h = (int) (w * r);
ExceptionHelpers.dLog(TAG, "Adapter Width : " + w + " Height : " + h + " R : " + r);
ExceptionHelpers.dLog(TAG, "Adapter Width : " + bitmap.getWidth() + " Height : " + bitmap.getHeight());
return Bitmap.createScaledBitmap(bitmap, w, h, false);
}
})*/
.build();
config = new ImageLoaderConfiguration.Builder(App.context)
.defaultDisplayImageOptions(options)
.memoryCacheSize(41943040)
.discCacheSize(104857600)
.threadPoolSize(10)
.build();
}
@Override
public int getCount() {
return size;
}
@Override
public JobItem getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
try {
if(convertView==null){
LayoutInflater vi = (LayoutInflater) App.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(UIHelpers.screen_density >= 4){
convertView = vi.inflate(R.layout.grid_ma_xl, null);
}else{
convertView = vi.inflate(R.layout.grid_ma_m, null);
}
holder = new ViewHolder();
holder.img =(ImageView) convertView.findViewById(R.id.img_image_gv_ma);
holder.imgVip = (ImageView) convertView.findViewById(R.id.img_vip_gv_ma);
holder.txtTitle = (TextView) convertView.findViewById(R.id.txt_title_gv_item);
holder.txtCat = (TextView) convertView.findViewById(R.id.txt_cat_gv_item);
holder.txtDesc = (TextView) convertView.findViewById(R.id.txt_desc_gv_item);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
Typeface tf = Typeface.createFromAsset(App.context.getAssets(), "b_yekan.ttf");
Typeface tf1 = Typeface.createFromAsset(App.context.getAssets(), "b_mitra.ttf");
holder.txtTitle.setTypeface(tf1);
holder.txtCat.setTypeface(tf);
holder.txtDesc.setTypeface(tf);
holder.txtTitle.setTextSize(UIHelpers.titleFont);
holder.txtCat.setTextSize(UIHelpers.descFont);
holder.txtDesc.setTextSize(UIHelpers.descFont);
if(objects.get(position).getjVip()==1) {
holder.imgVip.setVisibility(View.VISIBLE);
} else if (objects.get(position).getjVip()==0) {
holder.imgVip.setVisibility(View.INVISIBLE);
}
String imgURL = "";
imgURL = imgURL + objects.get(position).getjImage();
// ExceptionHelpers.dLog(TAG, "imgURL : '" + imgURL + "'");
/*if(imgURL.equals("http://www.yazdjobs.com/null") ||
imgURL.equals("http://www.yazdjobs.com/") ||
imgURL.equals("http://yazdjobs.com/null") ||
imgURL.equals("http://yazdjobs.com/")){
imgURL = "http://www.yazdjobs.com/wp-content/themes/yazdjobs/images/no-image.png";
}*/
// ExceptionHelpers.dLog(TAG, "imgURL : '" + imgURL + "'");
// ExceptionHelpers.dLog(TAG, "Position : "+position+" / "+objects.size());
// Show Images
// imageLoader.init(ImageLoaderConfiguration.createDefault(App.context));
imageLoader.init(config);
ImageAware imageAware = new ImageViewAware(holder.img, false);
imageLoader.displayImage(imgURL, imageAware, options);
/*Picasso.with(App.context)
.load(imgURL)
.placeholder(R.drawable.thumb_square)
.error(R.drawable.thumb_square)
.into(holder.img);*/
holder.txtTitle.setText(objects.get(position).getjTitle());
holder.txtCat.setText(objects.get(position).getjCatName());
if(UIHelpers.screen_density >= 4){
holder.txtDesc.setText(objects.get(position).getjDescLimit());
}else{
holder.txtDesc.setText(objects.get(position).getjDesc());
}
} catch (Exception e) {
ExceptionHelpers.catchMessage(e);
ExceptionHelpers.eLog(TAG, "Error in Grid Adapter >> " + e, e);
}
return convertView;
}
public class ViewHolder {
private ImageView img;
private ImageView imgVip;
private TextView txtTitle;
private TextView txtCat;
private TextView txtDesc;
}
}
我甚至尝试过ImageLoaderConfiguration但对我不起作用。 如何解决它