若是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);
}});