Implementing “withDelay” in Picasso Android (for skimming)

后端 未结 2 1733
南方客
南方客 2020-12-06 15:10

When dealing with many scrolling images, you have to avoid the problem of loading while skimming, while the user is fast scrolling. The simplest and often best solution is r

2条回答
  •  醉酒成梦
    2020-12-06 15:21

    The ability to pause/resume a request will be part of the next release of Picasso 2.4 Just yesterday a pull request containing this feature has been merged in the main branch. It allows to easily define a scroll listener that pauses/resume Picasso while flinging, as shown in the sample code reported below:

    public class SampleScrollListener implements AbsListView.OnScrollListener {
      private final Context context;
    
      public SampleScrollListener(Context context) {
        this.context = context;
      }
    
      @Override
      public void onScrollStateChanged(AbsListView view, int scrollState) {
        final Picasso picasso = Picasso.with(context);
        if (scrollState == SCROLL_STATE_IDLE || scrollState == SCROLL_STATE_TOUCH_SCROLL) {
          picasso.resumeTag(context);
        } else {
          picasso.pauseTag(context);
        }
      }
    
      @Override
      public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                           int totalItemCount) {
        // Do nothing.
      }
    }
    

提交回复
热议问题