I just want to fix the image on webview like the picture as shown below. I did something to achieve that and it works actually on new kind of handsets like HTC One, Samsung S2-S3-S4, etc. But for small screen devices like Galaxy Ace it doesnt work and It looks very tiny. For instance android image on the picture appears centerized but very small.
Here is what I did
webView = (WebView)findViewById(R.id.webView);
WebSettings settings = webView.getSettings();
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setJavaScriptEnabled(true);
String data = "<body><center><img width=\""+width+"px\" height=\""+height+"px\" src=\"" + url + "\" /></center></body></html>";
webView.loadData(data, "text/html", null);
width and height calculating
//linearWebview is the parent of webview, I calculated its width and height and set the image dimensions according to that values.
linearWebview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
width = linearWebview.getWidth();
height = linearWebview.getHeight();
}
});
So my question is why it doesnt work on small screen devices and how can I achive that problem?