若是SwipeRefreshLayout 直接包裹一个listView,滑动并不冲突。但是当SwipeRefreshLayout 里面包含了多个控件,这时候SwipeRefreshLayout 和 ListView 就有滑动冲突问题了。ide
思路: 监听listView的滚动事件,判断listView 第一条可见的item 是否为firstItem, 若是是则swp.setEnabled(true).net
lv_order.setOnScrollListener(new AbsListView.OnScrollListener() {事件
public void onScrollStateChanged(AbsListView view, int scrollState) {get
}it
public void onScroll(AbsListView view, int firstVisibleItem,List
int visibleItemCount, int totalItemCount) {scroll
boolean enable = false;layout
if(lv_order != null && lv_order.getChildCount() > 0){
// check if the first item of the list is visible
boolean firstItemVisible = lv_order.getFirstVisiblePosition() == 0;
// check if the top of the first item is visible
boolean topOfFirstItemVisible = lv_order.getChildAt(0).getTop() == 0;
// enabling or disabling the refresh layout
enable = firstItemVisible && topOfFirstItemVisible;
}
swp.setEnabled(enable);
}});