Android ListView - stop scrolling at 'whole' row position

前端 未结 7 1438
生来不讨喜
生来不讨喜 2020-12-29 11:46

Sorry for the confusing title, I cannot express the problem very concisely...

I have an Android app with a ListView that uses a circular / \"infinite\" adapter, whi

7条回答
  •  感情败类
    2020-12-29 12:12

    My Solution:

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
    
    {
    
        if (swipeLayout.isRefreshing()) {
            swipeLayout.setRefreshing(false);
        } else {
            int pos = firstVisibleItem;
            if (pos == 0 && lv_post_list.getAdapter().getCount()>0) {
    
                int topOfNext = lv_post_list.getChildAt(pos + 1).getTop();
                int heightOfFirst = lv_post_list.getChildAt(pos).getHeight();
                if (topOfNext > heightOfFirst) {
                    swipeLayout.setEnabled(true);
                } else {
                    swipeLayout.setEnabled(false);
                }
            }
            else
                swipeLayout.setEnabled(false);
        }
    }
    

提交回复
热议问题