2

I am trying to reach bottom of a Webview. I am getting the height of Webview inside onPageFinished() method by,

override fun onPageFinished(view: WebView?, url: String?) {

                Log.d("webview_total_height", "height " + view!!.contentHeight)
                height = view!!.contentHeight
            }

And on button click I am trying to reach to bottom by,

wvMain.scrollTo(0, height)

But it's scrolling to somewhere middle of webview, not reaching bottom

How will I reach to the bottom of webview?

4
  • try view.scrollTo(0, view.getContentHeight()); Commented Nov 24, 2018 at 19:44
  • Here, view is webview, right? Commented Nov 24, 2018 at 19:45
  • yes, it is webview Commented Nov 24, 2018 at 19:45
  • If you can extend WebView try overriding and exposing protected method computeVerticalScrollRange(). Commented Nov 24, 2018 at 19:47

1 Answer 1

3

Just replace

wvMain.scrollTo(0, height)

By

wvMain.scrollTo(0, height * getResources().getDisplayMetrics().density.toInt())

By this you will get actual height of WebView in pixels as per device screen density

I guess you will get your desired result.

Sign up to request clarification or add additional context in comments.

1 Comment

Right, it also makes sens to wait for the web content to load.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.