Search code examples
javaandroiduniversal-image-loader

Fast Scroll In ListView optimizing using UniversalImageloader or using references of Views


I am trying to make a TimeLine somewhat similar to Facebook or Instagram. More closer to Instagram. In Images loading i am using library UniversalImageLoader. Each of my ListView item row is probably more than 600dp in height. Usually I am fetching 5 items at a time.

The problem that occurs now is, The images when scroll a little fast replace each other. Since the views are being reused. It takes about 3-4 seconds for images to show up otherwise wrong images will be displayed in listView Row.

1- If anyone can know how to optimise/fix this fast scroll ImageOverlap issue Otherwise, 2- What is the way to record EntireView , let's say in some "ArrayList" and placing it at current position. Noting that there are quite other stuff happening too , not only mediaDp being changed.

    if (convertView == null)
    {
        view = inflator.inflate(R.layout.timeline_list_row, parent, false);
        viewHolder.userDp = (RoundedImageView) view.findViewById(R.id.userDp);

        viewHolder.mediaDp = (ImageView) view.findViewById(R.id.imagePostedMedia);

        /************ Set holder with LayoutInflater ************/
        view.setTag(viewHolder);
        final ViewHolder newHolder = viewHolder;

    }
    else
        viewHolder = (ViewHolder) view.getTag();

    imageLoader.displayImage(media.imagePath, viewHolder.mediaDp);

Solution

  • Try setting bitmap options for the imageview as follows.

    DisplayImageOptions  options = new DisplayImageOptions.Builder()
                            .showImageOnLoading(R.drawable.ic_stub)
                            .showImageForEmptyUri(R.drawable.ic_empty)
                            .showImageOnFail(R.drawable.ic_error)
                            .cacheInMemory(true)
                            .cacheOnDisc(true)
                            .considerExifParams(true)
                            .build();
    

    and now try diplay to imageview as

    imageLoader.displayImage(imageUrls[position], holder.image, options);
    

    I am sure this will work.

    See the code cacheInMemory(true) property for display options is important.