Android 解决WebView和ScrollView滚轮滑动冲突

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Greathfs/article/details/71336334

第一步,重写WebView的onGenericMotionEvent方法

/**
     * 滑轮处理
     */
    @Override
    public boolean onGenericMotionEvent(MotionEvent event) {
        if (callback != null)
            return callback.onGenericMotionEvent(event);
        return super.onGenericMotionEvent(event);
    }
      //定义一个接口,把滚动事件传递出去
    public interface GenericMotionCallback {
        boolean onGenericMotionEvent(MotionEvent event);
    }

    GenericMotionCallback callback;

    public void setCallback(GenericMotionCallback callback) {
        this.callback = callback;
    }

第二步,让对应的WebView对象调用之前setCallback这个方法,返回外部ScrollView的滚轮事件

mExpectIncomeWeb.setCallback(new WZWebView.GenericMotionCallback() {
            @Override
            public boolean onGenericMotionEvent(MotionEvent event) {
                return mScrollView.onGenericMotionEvent(event);
            }
        });

猜你喜欢

转载自blog.csdn.net/Greathfs/article/details/71336334