美文网首页
解决listview与SwipeRefreshLayout滑动冲

解决listview与SwipeRefreshLayout滑动冲

作者: ana生 | 来源:发表于2017-06-28 10:57 被阅读0次

本人最近发现还是有很多小伙伴会用listview,而放弃recyclerview,何弃疗?最近收到一位网友的热心问答,发现他在做listview和swiperefreshlayout嵌套的时候会产生冲突,没错,swiperefreshlayout目前只适配我大Recyclerview。废话不多说,直接上码给大家解决listview与swipe的滑动冲突问题,大家有问题欢迎咨询哈!

listView.setOnScrollListener(new OnScrollListener() {

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
    int visibleItemCount, int totalItemCount) {
boolean enable = false;
if(listView != null && listView.getChildCount() > 0){
    // check if the first item of the list is visible
    boolean firstItemVisible = listView.getFirstVisiblePosition() == 0;
    // check if the top of the first item is visible
    boolean topOfFirstItemVisible = listView.getChildAt(0).getTop() == 0;
    // enabling or disabling the refresh layout
    enable = firstItemVisible && topOfFirstItemVisible;
}
swipeRefreshLayout.setEnabled(enable);
}});

相关文章

网友评论

      本文标题:解决listview与SwipeRefreshLayout滑动冲

      本文链接:https://www.haomeiwen.com/subject/fvxucxtx.html