I am attempting to customize the onLayout function of a WebView in order to limit the size of large images to fit within the screen size. Within my extended WebView, I have tried the following code:
@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()+"'};");
}
});
}
Despite logging the new width when rotated, the image width is not being restricted as intended.