Issue
I'm trying to override the onLayout of a WebView, to restrict size of large images to the screen size. In my overridden WebView, I tried:
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
Log.d("WEBVIEW-WIDTH",""+getWidth());
post(new Runnable() {
@Override
public void run() {
loadUrl("javascript:var imgs = document.getElementsByTagName('img');"+
"for (var i=0; i<imgs.length; i++) {imgs[i].style.maxwidth='"+getWidth()+"'};");
}
});
}
When rotated, it logs the new width, but doesn't restrict the width of the image.
Solution
It wasn't working because I used maxwidth, not maxWidth.
Fortunately, it looks like there is a much better way to display it, which updates the image size when zooming and rotating:
img { max-width: 100%; }
From http://davidwalsh.name/image-max-width
Answered By - NoBugs
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.