javascript - Android WebView adding strange empty space at the bottom -


i'm trying add more empty space loaded webview using javascript.

i load data using loaddatawithbaseurl() string resource. then, after measuring content, need make webview bigger, 100 pixels. call javascript function using loaddatawithbaseurl():

mwebview.loadurl("javascript:addheight()"); 

javascript function defined in original html:

function addheight() { " +     var elemdiv = document.createelement('div');     elemdiv.style.csstext = 'height:100px;';      document.body.appendchild(elemdiv);  }  

after this, webview resizes fit new content. however, resulting height not originalsize + 100px, bigger. don't know where's problem. can't determine target size, because depends on size of appended div , different.

has tried this? familiar behaviour?

i found next solution. there used js callback. hope helps you. change in size should work better dynamic.

    private void setupwebview() {     webview.getsettings().setjavascriptenabled(true);     webview.setwebviewclient(new webviewclient() {         @override         public void onpagefinished(webview view, string url) {             webview.loadurl("javascript:myapp.resize(document.body.getboundingclientrect().height)");             super.onpagefinished(view, url);         }     });     webview.addjavascriptinterface(this, "myapp"); } @javascriptinterface public void resize(final float height) {     myactivity.this.runonuithread(new runnable() {         @override         public void run() {             webview.setlayoutparams(new linearlayout.layoutparams(getresources().getdisplaymetrics().widthpixels, (int) (height * getresources().getdisplaymetrics().density)));         }     }); } 

and of see paragraph 4 of list. luck!


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -