1.swipeRefreshLayout与webView滑动冲突解决方法:
重写webView,在onScrollChanged做逻辑判断
public class WebViewForScroll extends WebView {
private SwipeRefreshLayout swipeRefreshLayout;
public WebViewForScroll(Context context, SwipeRefreshLayout swipeRefreshLayout) {
super(context);
this.swipeRefreshLayout = swipeRefreshLayout;
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (this.getScrollY() == 0){
swipeRefreshLayout.setEnabled(true);
}else {
swipeRefreshLayout.setEnabled(false);
}
}
}
为了避免莫名其妙的异常,动态添加webView
WebViewForScroll webView = new WebViewForScroll(getActivity(),swipeRefreshLayout);
ll_web = (LinearLayout) view.findViewById(R.id.ll_web);
ll_web.addView(webView);
以下是布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/titleBar"
layout="@layout/layout_titlebar" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/ll_web"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/mProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="2dp"
android:indeterminateOnly="false"
android:max="100"
android:progressDrawable="@drawable/webview_progressbar_states" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
2.swipeRefreshLayout与ListView滑动冲突解决方法:
SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.bottombar_blue));
swipeRefreshLayout.setOnRefreshListener(myOnRefreshListener);
/*
*下拉刷新监听
*/
private SwipeRefreshLayout.OnRefreshListener myOnRefreshListener = new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//1.5秒后执行刷新
handler.postDelayed(new Runnable() {
@Override
public void run() {
//添加数据源
swipeRefreshLayout.setRefreshing(false);
}
},1500);
}
};
/*
*解决listView与swiperefreshlayout滑动冲突
*/
private AbsListView.OnScrollListener myOnScrollListener = new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
boolean enable = false;
if(lv_sbxm != null && lv_sbxm.getChildCount() > 0){
// check if the first item of the list is visible
boolean firstItemVisible = lv_sbxm.getFirstVisiblePosition() == 0;
// check if the top of the first item is visible
boolean topOfFirstItemVisible = lv_sbxm.getChildAt(0).getTop() == 0;
// enabling or disabling the refresh layout
enable = firstItemVisible && topOfFirstItemVisible;
}
swipeRefreshLayout.setEnabled(enable);
}
};