ListView scrolling using UniversalImageDownloader not smooth

江枫思渺然 提交于 2019-12-03 08:34:31

I had the same issue with image downloading. I solved it by setting delayBeforeLoading(1000) in my DisplayImageOptions. It is needed to start downloading when user stop fling.

so try to replace your getDisplayOptions method with this

 public static DisplayImageOptions getDisplayOptions() {

     DisplayImageOptions options = new DisplayImageOptions.Builder()
    .showImageForEmptyUri(R.drawable.error)
    .showImageOnFail(R.drawable.error)
    .delayBeforeLoading(1000) 
    .resetViewBeforeLoading(false)  // default
    .cacheInMemory(true) // default
    .cacheOnDisc(true) // default
    .build();

    return options;
}

Documentation also recommends to use this code to avoid grid/list view scroll lags

boolean pauseOnScroll = false; // or true
boolean pauseOnFling = true; // or false
PauseOnScrollListener listener = new PauseOnScrollListener(imageLoader, pauseOnScroll, pauseOnFling);
listView.setOnScrollListener(listener);

You can read it here (the last item of "Useful Info" list)

So you can use one of this methods

DroidFox

@Sergey Pekar: You saved my life! :) I always used UIL for ListView for a small count of images, but then as the count got bigger I got always a lag on the first load (while scrolling) of the images. So I also tried the delay and it helped a little bit and other UIL configs and options, but I was not happy. Then I've tried different Image-Loading-Libraries (Picasso, AQuery, Volley, UrlImageViewHelper, custom code). They all worked faster(on first load) than UIL but they did not have enough options for me. So I looked for the last 2 days for a solution regarding this lag-problem and thanx god I finally found your post here! The solution was the PauseOnScrollListener!

What also (addtionally to the PauseOnScrollListener) improves a little bit the scroll-smoothness is by extending the ImageView to stop requestLayout like this:

public class CustomImageView extends ImageView
{
    public CustomImageView (Context context, AttributeSet attributeset, int int_style)
    {
        super(context, attributeset, int_style);
    }

    public CustomImageView (Context context, AttributeSet attributeset)
    {
        super(context, attributeset);
    }

    public CustomImageView (Context context)
    {
        super(context);
    }

    @Override
    public void requestLayout() 
    {
        // Do nothing here
    }
}

For more info see this post:
ListView very slow when scrolling (using ViewHolder/recycling)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!