Nitin Gaikwad
Nitin Gaikwad

Reputation: 23

Android Scroll and Webview scroll

I am implementing one application.

On one screen there is webview + Other stuff and that activity layout have scroll enabled.

When I open the page in webview and if that also have the scroll enabled then it fails.

The native(android scroll) override the webview scroll and i am unable to scroll to webview. So is there any way to solve this issue?

I added following setting for webview

webview.setVisibility(View.VISIBLE);
webview.setVerticalScrollBarEnabled(true);
webview.setHorizontalScrollBarEnabled(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.setWebViewClient(new WebViewClient() );
webview.loadUrl(strUrl);
webview.getSettings().setJavaScriptEnabled(true);

Upvotes: 0

Views: 1052

Answers (2)

Cyph3rCod3r
Cyph3rCod3r

Reputation: 2086

Create a custom ScrollView and try to intercept touch of the child which is your WebView

 public class CustomScrollView extends ScrollView {
    private GestureDetector mGestureDetector;

    public CustomScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mGestureDetector = new GestureDetector(context, new YScrollDetector());
        setFadingEdgeLength(0);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
    }

    // Return false if we're scrolling in the x direction  
    class YScrollDetector extends SimpleOnGestureListener {
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {             
            return Math.abs(distanceY) > Math.abs(distanceX);
        }
    }
}

Upvotes: 0

Bhushan
Bhushan

Reputation: 109

if you set fixed height to webview than you 'll able to use both scroll view with web view. Else no any other option that make good work with webview inside the scroll view

Upvotes: 1

Related Questions