ListView scrolling using UniversalImageDownloader not smooth

后端 未结 2 1259
长发绾君心
长发绾君心 2021-02-10 13:57

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 15:02

    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

提交回复
热议问题