Android: onScrollStateChanged SCROLL_STATE_IDLE sometimes doesn't fire

前端 未结 3 1709
悲&欢浪女
悲&欢浪女 2021-02-05 23:00

I\'m running into a bit of a problem. What I\'m doing: I\'ve got a ListView which has got some images in it. To make the scrolling smoother I\'ve disabled the images to show up

3条回答
  •  悲哀的现实
    2021-02-05 23:08

    I had the same problem, so my solution was to just detect if the scrollview position has reached the last page and in that case always load the images regardless of the scroll state (since the problem seems to always occur when the user flings to the end of the listview). So modifying your code you would have:

    mList.setOnScrollListener(new OnScrollListener() {
    
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            mListAdapter.setIsScrolling(scrollState != SCROLL_STATE_IDLE);
            Log.i(this, "scrollStateChanged" + scrollState);
    
            int first = view.getFirstVisiblePosition();
            int count = view.getChildCount();
    
            if (scrollState == SCROLL_STATE_IDLE || (first + count > mListAdapter.getCount()) ) {
                mList.invalidateViews();
            }
        }
    
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        }
    });
    

提交回复
热议问题