smoothScrollToPosition() only scrolls partway in Android ICS?

前端 未结 5 1887
闹比i
闹比i 2021-02-04 18:05

In Gingerbread, I had no issues with using smoothScrollToPosition() to scroll across dozens of items at a time. After my Nexus S was upgraded to Ice Cream Sandwich, I noticed th

5条回答
  •  春和景丽
    2021-02-04 19:07

    This is what I did to resolve the issue. Essentially, we want to keep calling smoothscrolling until you reach the desired element (in this case, I simply want to scroll to the top, which is element 0).

    //There is a known bug where smoothScrollToPosition(..) may not reach the top, 
                //if the list is very large, keep scrolling until you reach the top element
                newsFeed.setOnScrollListener(new OnScrollListener() {
                    @Override
                    public void onScrollStateChanged(AbsListView view, int scrollState) {
    
                    }
    
                    @Override
                    public void onScroll(AbsListView view, int firstVisibleItem,
                            int visibleItemCount, int totalItemCount) {
                        if(firstVisibleItem != 0) {
                            newsFeed.smoothScrollToPosition(0);
                        } 
                        else {
                            //We are done
                            newsFeed.setOnScrollListener(null);
                        }
                    }
                });
                newsFeed.smoothScrollToPosition(0);
    

提交回复
热议问题