How to Shrink WebView size dynamically according to its content?
Seems there's no way to resize the WebView(decrease) its size dynamically once its loaded. So, the only thing that could solve my problem was reloading the complete WebView.
So, instead of defining the Fragment in XML, I changed my stuff by adding Fragment dynamically every time. By which I was able to solve my issue.
How to resize the webview According to the size of device Screen in android studio
Both are the same.
Both are correct in terms of functionality.
You can choose anyone of them.
A.
Settings of webview is being modified by directly referencing from the view
B. Its taking the WebSettings
object first and then modifying its state.
android resize webView
Layout in android is asynchronous. Try overriding the WebView onSizeChanged method to get notified when the webview's size changes. Alternatively you could also use a ViewTreeObserver but that's less efficient.
The WebView gets the size from it's view parent. Since you're not attaching the webview to a view it won't get sized at all and you need to force that by calling
webview.layout(0, 0, width, height);
note that the above is only one of the many methods that get called on the webview when it's in the view hierarchy. The implementation might change to depend on more/different calls in the future. A more future-proof way would be to insert the webview into your view hierarchy and set it's visibility to INVISIBLE.
How do I Resize my WebView in Activity?
i think there is that you should look these two questions
WebView doesn't resize
but from that i see you need to create new WebView every time
WebView height = wrap_content with changing font size doesn't work
And the answers too...
EDIT for creating new webview programmatically
Webview in programmatically created RelativeLayout
and this also Im trying to programmatically insert a WebView into my Code
How to resize the webview According to the size of device Screen (Or Width) in android
Finally I sorted out my solution myself. Here it is
holder.webView.loadDataWithBaseURL(null,"<!DOCTYPE html><html><body style = \"text-align:center\"><img style=\"border-style:dotted;border-width:5px;border-color:black;width:99%;\" src= " + URLs.get(position)+ " alt=\"page Not Found\"></body></html>","text/html", "UTF-8", null)
it will exactly fit the webView's tag fill the screen. no matter your phone is 230X480 or u have any android tablet of 800X1200 .
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.
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>
Related Topics
How to Open Navigation Drawer with No Actionbar, Open with Just a Button
Changing the Screen Brightness System Setting Android
Using an Android Library Project Activity Within Another Project
How to Implement the Deprecated Methods of Notification
Using Webview Sethttpauthusernamepassword
How to Get the File *.Apk Location in Android Device
Select Distinct Value in Android SQLite
Can Gradientcolor Be Used to Define a Gradient for a Fill or Stroke Entirely in Xml
How to Set Searchview Textsize
How to Change the Generated Filename for App Bundles with Gradle
How to Use Selector to Tint Imageview
Why Is Calling Process.Killprocess(Process.Mypid()) a Bad Idea
Firebase: How to Set Default Notification Channel in Android App
Why Is Calling Process.Killprocess(Process.Mypid()) a Bad Idea