1

I have a Webview that is embedded inside a scrollview. The Webview itself has areas that are vertical scrollable.

Now if I try to scroll inside the webview, the scrollview intercepts the touchevent and scrolls the whole webview instead that only the small scrollable div is moved.

How can I make the scrollview work only if the webview does not want to scroll?

Charles
  • 50,943
  • 13
  • 104
  • 142
Janusz
  • 187,060
  • 113
  • 301
  • 369
  • hello @Janusz I m facing same problem. did you find solution for that? if yes please post as your answer – Zombie Jun 29 '12 at 09:21

4 Answers4

0

@Janusz, I have had the same problem. My solution is based on the extended scroll view behaviour in couple with the correct layout. I have wrote the answer to the same question here. Let me know in case you have implementation problems or questions and, please inform whether it helps :)

Community
  • 1
  • 1
rus1f1kat0R
  • 1,645
  • 1
  • 16
  • 22
0

In my case, I have a webview within a scrollview container, and the scrollview and webview are full screen. I was able to fix this by overriding the onTouch event in my webView touchListener.

   scrollView = (ScrollView)findViewById(R.id.scrollview); 

   webView.setOnTouchListener(new OnTouchListener() {           
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            scrollView.requestDisallowInterceptTouchEvent(true);
            return false;
        }
   }
Derek Wade
  • 697
  • 8
  • 11
0

Use TouchyWebView.java

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

In layout file:

<yourclasapath.TouchyWebView 
                android:id="@+id/description_web"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                 />
Makvin
  • 3,475
  • 27
  • 26
-1

Our solution uses a Javascript callback through the Javascript Interface. Every time a part of the UI that is scrollable inside the WebView is touched a listener is called through java script and this listener calls requestDisallowInterceptTouchEvent on the WebViews parent.

This is not optimal but the nicest solution found at the moment. If the user scrolls very fast the layer in the WebView won't scroll but at a normal scroll rate it works fine.

Janusz
  • 187,060
  • 113
  • 301
  • 369