Stop when WebView is at the end

2019-09-02 17:07发布

问题:

I want to be able to scroll the webview until it has reached the end of the Webview. But the code below continues to scroll down automatically even when the webview page has reached to it's end. I want to make sure that each page scrolls down until the end of the webview.

webview.loadUrl("file:///android_asset/"+position+".html");
            webview.getSettings().setBuiltInZoomControls(true);
            webview.setPictureListener(new PictureListener() {

                public void onNewPicture(WebView view, Picture picture) {
                    int webBot = webview.getBottom();

                    webview.scrollBy(0, 1);
                }
            });

回答1:

Try this, (Basically using onPageFinished() instead of onNewPicture())

       wv.setWebViewClient(new WebViewClient() {            
        @Override
        public void onPageFinished(WebView view, String url) {
             // TODO Auto-generated method stub
            super.onPageFinished(view, url);
            Log.i(TAG,"onPageFinished invoked!!");
            wv.scrollBy(0, wv.getBottom());
            }

    });