Can Android's WebView automatically resize huge images?
Yes, it's possible. You can try setting the WebView Layout using the code below. It resizes all Images (Greater than the Device Screen Width
) to the Screen Width. This works for both Orientations (Portrait and Landscape)
webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
You can add extra margins/padding later to get the spacing right.
Android Webview: Images that are too large for the screen
I ended up using:
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
To make the contents of the page fit to the WebView.
resize image in webview in Android
To fit the image to the screen width, just comment
max-height: 100%;
To fit the image to the screen height, just comment
max-width: 100%;
That's all, there's no need to touch the android java code, just add the code above to your html document.
How to fit web images to Android screen size inside a WebView? while getting content of a site using JSON data, using restful
I have finally solved it by setting the style tag with the web content.
webViewLoader.setLoadDataWithBaseUrl("<style>img{display: inline;height: auto;max-width: 100%</style>"+ParentObject.getJSONObject("content").getString("rendered"));
If someone wants to add any more style just add <style></style>
after or before <style>img{display: inline;height: auto;max-width: 100%</style>
Android - Webview scale image to fit biggest dimension
Try #5 Worked!!!
int iMW = imgView.getMeasuredWidth();
int iMH = imgView.getMeasuredHeight();
//Had the imw and iw backward...same for height
int scW = (int) ((iMW / (float)iW) * 100);
int scH = (int) ((iMH / (float)iH) * 100);
int fScale = 0;
if (iMW < iW && iMH < iH)
{
if (scW < scH)
{
fScale = scW;
}
else
{
fScale = scH;
}
}
if (iMW < iW && iMH > iH)
{
fScale = scW;
}
if (iMW > iW && iMH < iH)
{
fScale = scH;
}
//had signs backwards...DUH
if (iMW > iW && iMH > iH)
{
if (scW < scH)
{
fScale = scW;
}
else
{
fScale = scH;
}
}
wView.setInitialScale(fScale);
wView.loadUrl(pUrl);
Related Topics
How to Change Package Name in Android Studio
How to Open the Options Menu Programmatically
How to Wrap Lengthy Text in a Spinner
Custom Converter for Retrofit 2
Android Opengl Es Transparent Background
How to Get Documents in an Android Directory That Phonegap Will See
Android Multiple Selection Listview & Textview
How to Make a Edittext Box in a Dialog
How to Attach Android Source to Eclipse
How to Automatically Uninstall Android App from Device Before Installing a New Version
Com.Google.Android.Gsf Package Couldn't Be Found
What Is the Alternative to Android Orientation Sensor
Checking a Checkbox in Listview Makes Other Random Checkboxes Checked Too
Detect When Android V2 Maps Has Loaded