Add view at end of webview

guys! I have googled all day, however, I cannot find a solution. So, I post my question here, hope to get some blow.

I want to add an empty area to the end of the web browser in android, I am trying to install the bottom webview add-on, however this does not work. I know that the webview layout is absolute, which is deprecated, and I tried to get the entire length of the web view and add the view at the end, I try to use getContentHeight (), however the height is not quite right, this is not the end of the web view, maybe because of the picture or something else, I don’t know.

So my question is, is there anyway to achieve my original goal, which adds some blank area at the end of the web view?

Thanks in advance!

+7
android webview
source share
3 answers

I have done something similar before, but I think it should work.

  • Create your own class that extends the web view (say CustomWebView)

  • Override onmeasure

eg.

public void onMeasure(int wspec, int hspec){ super.onMeasure(wspec, hspec); this.setMeasuredDimension(this.getMeasuredWidth(), this.getMeasuredHeight() + 200); // the padding you need. } 
+3
source share

Two days later Google and trying, I finally get what I want, thanks xandy, your method gives me a hit.

Here is my solution. I did not override the OnMeasure method, instead I override the computeVerticalScrollRange method, so it will increase the entire vertical length of the webview. Just like adding a little empty area at the end.

following code:

 protected int computeVerticalScrollRange() { float density = getResources().getDisplayMetrics().density; return super.computeVerticalScrollRange()+(int)(60*density); } 

Thanks again xandy.

+3
source share

Not all solutions worked for me here, so I chose a different route: to add an addition to the contents of the WebView , and not the WebView itself, I did this only using JavaScript.

When the page finished loading, I used the following code:

 loadUrl("javascript:document.getElementsByTagName('body')[0].style.paddingBottom='" + mPadding + "px'"); 

You must be careful when changing the CSS of a loadable web page. It worked in my case.

-one
source share

All Articles