webView手势上拉没问题,下拉会执行SwipeRefreshLayout 的刷新操作,
解决办法:自定义Webview重写手势
package com.yinuo.mancai.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.webkit.WebView;
/**
* Created by yangfan
* nrainyseason@163.com
*/
public class MyWebView extends WebView{
private ViewGroup viewGroup;
public MyWebView(Context context) {
super(context);
}
public MyWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ViewGroup getViewGroup() {
return viewGroup;
}
public void setViewGroup(ViewGroup viewGroup) {
this.viewGroup = viewGroup;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
if(this.getScrollY() <= 0)
this.scrollTo(0,1);
break;
}
return super.onTouchEvent(event);
}
}然后在SwipeRefreshLayout 的setOnChildScrollUpCallback监听中判断,setOnChildScrollUpCallback这个监听要24以上的包下才有
mWebView.setViewGroup(SwipeRefreshLayout);
private void initListener() {
SwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mWebView.reload();
SwipeRefreshLayout.setRefreshing(false);
}
});
SwipeRefreshLayout.setOnChildScrollUpCallback(new SwipeRefreshLayout.OnChildScrollUpCallback() {
@Override
public boolean canChildScrollUp(SwipeRefreshLayout parent, @Nullable View child) {
return mWebView.getScrollY()>0;
}
});
}这样就能解决问题了
当SwipeRefreshLayout嵌套WebView时,下拉操作会导致SwipeRefreshLayout的刷新动作。为了解决这个问题,可以自定义WebView并重写手势处理,同时在SwipeRefreshLayout的setOnChildScrollUpCallback监听中进行判断。这个解决方案适用于API 24及以上版本。

767

被折叠的 条评论
为什么被折叠?



