Android 解决SwipeRefreshLayout与ListView和ScrollView滑动冲突

SwipeRefreshLayout与ScrollView滑动冲突:

	scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
			@Override
			public void onScrollChanged() {
				if (swipeLayout != null) {
					swipeLayout.setEnabled(scrollView.getScrollY() == 0);
				}
			}
		});
SwipeRefreshLayout与ListView滑动冲突:

listView.setOnScrollListener(new OnScrollListener() {

			@Override
			public void onScrollStateChanged(AbsListView arg0, int arg1) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onScroll(AbsListView arg0, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
				// TODO Auto-generated method stub
				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;
				}
				swipeLayout.setEnabled(enable);
			}
		});


猜你喜欢

转载自blog.csdn.net/superyu1992/article/details/60579548