Search code examples
androidandroid-listviewandroid-arrayadapterandroid-gridviewuniversal-image-loader

GridView Thumbnails refreshed when scrolling


In my Android app I´m using Universal Image Loader library for showing photos from the SD card in the GridView. I also set cacheInMemory(true) (like here: UIL).

For showing the pictures I´m using ArrayAdapter with ViewHolder pattern.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    ViewHolder holder = null;

    File item = data.get(position);

    if (row == null) {
        holder = new ViewHolder();

        row = mInflater.inflate(layoutResourceId, null);

        holder.image = (ImageView) row.findViewById(R.id.picture);

        row.setTag(holder);
    } else {
        holder = (ViewHolder) row.getTag();
    }

    if (item.isFile()) {
      String uri = Uri.fromFile(f).toString();
      String decodedUri = Uri.decode(uri);

      Globals.ImageLoader.displayImage(decodedUri, holder.image);
    }

    return row;
}

When scrolling through the library, thumbnails are refreshing every time you scroll past them, and refreshing when scrolling past them again. And it´s not very comfortable for user. I want save the images to the memory and load them quickly.

Is it possible?


Solution

  • I added some others params to the UIL:

    .imageScaleType(ImageScaleType.EXACTLY)

    .bitmapConfig(Config.RGB_565)

    and

    .memoryCacheSizePercentage(50)

    From config and it´s look ok.