android - make webview content always fit width of the screen -
i have webpage has data in table want make viewable in android app through webview. problem table varies in width, 400px 1000px. trying make regardless of width, table fills webview user doesnt have zoom in or out, or scroll horizontally. have working on galaxy s2, on other devices nexus 5x, page starts zoomed way out , user has zoom in read anything. zoomed out, content filling 50% of screen , don't know space coming from.
here have setup make work on galaxy s2:
html:
<meta name="viewport" content="width=device-width, initial-scale=.1" />
this made started zoomed way out, when content 400px wouldn't zoomed way out.
android webview:
websettings settings = w.getsettings(); settings.setjavascriptenabled(true); settings.setallowfileaccess(true); settings.setbuiltinzoomcontrols(true); settings.setdisplayzoomcontrols(false); settings.setusewideviewport(true);
usewideviewport way allow user zoom out enough not have scroll horizontally.
here looks on galaxy s2, how page loads , user cannot zoom out anymore, when page has table (not in screenshot) same page zoomed out further fit table takes 100% of screen width. how want it:
the same page on nexus 5x looks this, way zoomed out, , when table there doesn't take half of width of screen:
any appreciated, iv'e tried messing config / meta tags lot work on galaxy.
setting table 100% makes stretch fill nexus screen, makes text small , columns far apart.
edit: clarify, took horizontal screenshots because know if content isn't wide enough fit device screen @ normal zoom add whitespace, , that's fine. problem both screenshots zoomed out far can be, i'd know why second able zoom out far,and how prevent it.
edit2: temporary fix, have set viewport width 1 of 2 values depending on if screen going wide or narrow. set 100% width, viewport width either set 400 or 1000 depending on whether or not content of table larger:
<meta name="viewport" content="width=<?php echo ($widecontent?"1000":"400"); ?>, initial-scale=.1" />
this working now, in future going need more widths , better if automatically adjusted.
Comments
Post a Comment