Android WebView - 如何在页面完成后滚动WebView?

时间:2018-02-10 14:27:50

标签: java android webview

我有一个webview个应用。我面临的问题是它没有在页面上完成。它应该在页面完成后上升,但它会卡在中心。请帮帮我!

不工作

            webView.setWebViewClient(new WebViewClient() {
                public void onReceivedError(WebView view, int errorCode,
 String description, String failingUrl) {

                @Override
                public void onPageFinished(WebView view, String url) {
                    if (pageFinished) {
                        swipe.setRefreshing(false);
                        animate(view);
                        showFreeze = false;
                    webView.setVisibility(View.VISIBLE);
                }

                if (url.contains("error.html")) {
                    currentUrl = "https://website";

                } else {
                    currentUrl = url;

                }

                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        pageFinished = true;

/////////////////////////// THIS ONE NOT WORKING /////////////////////////////
                        webView.pageUp(true);
                    }
                }, 250);
                super.onPageFinished(view, url);
            }
        });
    }

1 个答案:

答案 0 :(得分:0)

 @Override
    public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
        super.doUpdateVisitedHistory(view, url, isReload);

        try {
            mWebView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mWebView.scrollTo(0, 0);
                }
            }, 200);
        }catch (Exception ignored){}

    }

希望对您有所帮助。