要解决android SwipeRefreshLayout不允许WebView滚动的问题,可以尝试以下解决方法:
SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(false);
WebView webView = findViewById(R.id.webView);
webView.setOnTouchListener(new View.OnTouchListener() {
private float mLastY;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mLastY = event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
float deltaY = event.getRawY() - mLastY;
mLastY = event.getRawY();
// 判断WebView是否滚动到顶部或底部,如果是则允许SwipeRefreshLayout拦截滚动事件
if ((webView.getScrollY() == 0 && deltaY > 0) || (webView.getScrollY() >= (webView.getContentHeight() * webView.getScale()) - webView.getHeight() && deltaY < 0)) {
swipeRefreshLayout.setEnabled(true);
} else {
swipeRefreshLayout.setEnabled(false);
}
break;
}
return false;
}
});
以上方法可以解决android SwipeRefreshLayout不允许WebView滚动的问题。根据具体情况选择适合的解决方法。