ListView scrolling using UniversalImageDownloader not smooth

后端 未结 2 1328
星月不相逢
星月不相逢 2021-02-10 13:58

I am using a ListView containing images. These images are loaded from the Internet inside the adapter. Therefore I am using the UniversalImageDownloader.

<
相关标签:
2条回答
  • 2021-02-10 14:46

    @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)

    0 讨论(0)
  • 2021-02-10 14:53

    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

    0 讨论(0)
提交回复
热议问题