Android WebView inside ScrollView scrolls only scrollview

前端 未结 7 590
無奈伤痛
無奈伤痛 2020-11-27 02:26

In my app I have a ScrollView that contains some linearviews, some textviews and One Webview, then other linear layouts etc. The problem is that the WebView does not scroll.

7条回答
  •  天命终不由人
    2020-11-27 03:11

    Here is the solution. Found online. I have subclassed WebView and i'm using the requestDisallowInterceptTouchEvent(true); method to allow my webview to handle the scroll event.

    TouchyWebView.java

    package com.mypackage.common.custom.android.widgets
    
    public class TouchyWebView extends WebView {
    
        public TouchyWebView(Context context) {
            super(context);
        }
    
        public TouchyWebView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public TouchyWebView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent event){
            requestDisallowInterceptTouchEvent(true);
            return super.onTouchEvent(event);
        }          
    }
    

    And in layout.xml

    
    

提交回复
热议问题