2016-10-20 6 views
0

私のwebviewは正しくスクロールしません。私は画面上で1本の指を押し、別の指でスクロールするだけでスクロールします。 1本の指を取り除くとスクロールしません。私はそれが奇妙で愚かに聞こえることを知っている。ここでは、レイアウトのための私のコードはandroid webview奇妙なスクロール動作

<?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> 

これは私が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; 
      } 
     }); 

答えて

1

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

ここrequestDisallowInterceptTouchEvent(true);方法以下、カスタマーを使用してみてくださいイベント。

+0

ご回答いただきありがとうございますが、動作しませんでした – mSapps