简体   繁体   English

Android WebView奇怪的滚动行为

[英]android webview strange scrolling behaviour

My webview doesn't scroll properly . 我的网络视图无法正常滚动。 It scroll only , when I press one finger on the screen and scroll using another finger . 仅当我在屏幕上按下一个手指并使用另一根手指滚动时,它才会滚动。 It doesn't scroll when I remove one finger(which one is used to press) . 当我移开一根手指(用来按的手指)时,它不会滚动。 I know it sounds strange and silly . 我知道这听起来很奇怪而且很愚蠢。 Here is my code for layout 这是我的布局代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:clickable="false"
              android:orientation="vertical">  
    <ScrollView
        android:id="@+id/childScroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.surroundapps.watchme.util.NestedWebView
            android:id="@id/web_view_"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </ScrollView>
</LinearLayout>

This is how I set up webview 这就是我设置webview的方式

  WebView webView = (WebView) view.findViewById(R.id.web_view_);
        webView.setVerticalScrollBarEnabled(true);
        webView.setHorizontalScrollBarEnabled(true);
        WebSettings settings = webView.getSettings();
        settings.setDomStorageEnabled(true);
        settings.setJavaScriptEnabled(true);
        settings.setLoadWithOverviewMode(false);
        settings.setUseWideViewPort(false);
        settings.setSupportZoom(false);
        settings.setBuiltInZoomControls(true);
        settings.setDisplayZoomControls(true);
        webView.setWebViewClient(new WebViewClient()
        {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                return super.shouldOverrideUrlLoading(view, url);
            }

            @Override
            public void onPageFinished(WebView view, final String url)
            {
            }
        });

        webView.loadUrl(getUrl());

        ScrollView childScroll = (ScrollView) view.findViewById(R.id.childScroll);


        childScroll.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                // Disallow the touch request for parent scroll on touch of child view
                v.getParent().requestDisallowInterceptTouchEvent(true);
                return false;
            }
        });

Try using the following custome WebView 尝试使用以下自定义WebView

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);
    }          
}

Here requestDisallowInterceptTouchEvent(true); 这里requestDisallowInterceptTouchEvent(true); method will allow webview to handle the scroll event. 方法将允许Webview处理滚动事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM