具有UIL刷新问题的奇怪ListView

时间:2015-02-05 02:47:48

标签: android android-listview android-gridview

只要图片进入视图,ListView就会始终显示不同的图片,然后再更改回正确的图片。 我确实理解这种观点是回收利用,但为什么要这样做呢?

Gallery应用或QuickPic应用都没有此行为。这个应用程序快速加载,也不会占用大量内存。

发生什么事了?如何让它像QuickPic或Gallery一样表现?

适配器类:

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {       
      ViewHolder viewHolder = new ViewHolder();

      LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      if (convertView == null) {
          convertView = inflater.inflate(R.layout.gridview_layout, parent, false);

          viewHolder.imageView = (ImageView)convertView.findViewById(R.id.GridViewImage); 
          convertView.setTag(viewHolder);            
      } 
      else
      {  
          viewHolder = (ViewHolder)convertView.getTag();
      }

      GridViewImageLoader.getImageLoader(mContext).displayImage(getItem(position).getImageUrl(), viewHolder.imageView);


      return convertView;
    }

ImageLoader类:

public class GridViewImageLoader {

    private GridViewImageLoader(){   }

    public static ImageLoader getImageLoader(Context context){
        try {
            if (ImageLoader.getInstance().isInited()) {
                return ImageLoader.getInstance();
            }
            DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
            .showStubImage(R.drawable.automatic_icon)
            .showImageForEmptyUri(R.drawable.ic_empty)
            .showImageOnFail(R.drawable.ic_error)
            .cacheInMemory(true)
            .cacheOnDisc(true)
            .considerExifParams(true)
            .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
            .bitmapConfig(Bitmap.Config.RGB_565) // default
//            .decodingOptions()
            .displayer(new SimpleBitmapDisplayer()) // default
            .handler(new Handler()) // default
            .build();

            ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY)
            .denyCacheImageMultipleSizesInMemory()
            .discCacheFileNameGenerator(new Md5FileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.LIFO)
            .defaultDisplayImageOptions(defaultOptions).build();

            ImageLoader.getInstance().init(config);
            return ImageLoader.getInstance();
        } catch (Exception ex) {
            return null;
        }
    }
}

非常感谢

1 个答案:

答案 0 :(得分:-1)

尝试:

viewHolder.imageView.setImageResource(0); 
在你打电话之前

GridViewImageLoader.getImageLoader(mContext).displayImage(getItem(position).getImageUrl(), viewHolder.imageView);