简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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