在SwipeRefreshLayout、ViewPager,容器控件中内嵌了webview,webview的头部banner横向滑动跟viewpager冲突,可以采用如下自定义的webview来完美解决。
public class CloudsBannerWebView extends WebView {
public CloudsBannerWebView(Context context) {
super(context);
}
public CloudsBannerWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CloudsBannerWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CloudsBannerWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public CloudsBannerWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
super(context, attrs, defStyleAttr, privateBrowsing);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
getParent().getParent().requestDisallowInterceptTouchEvent(true);
}
return super.onTouchEvent(event);
}
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
if(clampedX){
getParent().getParent().requestDisallowInterceptTouchEvent(false);
}
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
}
}