Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a view at the end of Webview

guys! I have googled a whole day,still,I can not find a solution.So, I post my question here,hope to get some hit.

I want to add some blank area at the end of a webview in android, I try to set the bottom padding of webview,however, it doesn't work. I know the layout of webview is absoluteLayout,which is deprecated, and I tried get the whole length of webview,and add a view at the end, I try to use getContentHeight(), however, the height is not quite correct, it is not end of webview,maybe because of picture or something else, I do not know.

So,my question is,is there anyway to achieve my original goal, which is add some blank area at the end of a webview?

Thanks in advance!

like image 944
dape Avatar asked Nov 25 '10 02:11

dape


2 Answers

I did something similar before, but I think it should work.

  1. Create a custom class that Extend the Webview (say CustomWebView)

  2. Override onMeasure

e.g.

public void onMeasure(int wspec, int hspec){
    super.onMeasure(wspec, hspec);

    this.setMeasuredDimension(this.getMeasuredWidth(), this.getMeasuredHeight() + 200); // the padding you need. 
}
like image 112
xandy Avatar answered Nov 17 '22 19:11

xandy


After two days google and trying, I finally get what I want, thanks xandy,your method do give me a hit.

Here is my solution. I did not override OnMeasure method, instead , I override computeVerticalScrollRange method, so ,it will increase the whole vertical length of webview . Just like add some blank area at the end.

the following is my code:

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

Thanks again xandy.

like image 44
dape Avatar answered Nov 17 '22 19:11

dape