Currently I'm about to display HTML data into my application with fragment. I'm confused of which one I need to use to get better performance between TextView or WebView. I mean, for rendering speed and memory issue.
Know that Html.fromHtml() is available for TextView to display HTML formatted data but I want to try WebView instead of TextView. But don't know rendering speed and memory issue.
WebView internally provides different functionality for the display Html data. Also you can use JavaScript in WebView.
While TextView when you are use Html.fromHtml() then its support only few Html tags.
So I think its better to use WebView.
I just mentioned JavaScript functionality but There are other functionality like (Zoom Functionality, Image from web, etc..) All supports in WebView.
depends for what you wish to use it.. if you are loading website and want all the features of that website to be available you should use webview. If you are only displaying one html snippet you should use textview
Related
I used the android device monitor to check different News Reader UI and I realized that almost all of them are using Native components (ImageView, TextView, FrameLayout) to display their article instead of a WebView. I was wondering what could have motivated such a choice ?
A webService could return the article with a property containing the extracted and formatted html then the webView could be loaded from this plain html String with java webView.loadData("<div></di>", .., ..) right?
Rendering a webview is slower than calling a web service . If you render webview it will load a whole lot component like css, javascript . But If you call web service , you will only get the data you want and then populate other component like textview , image view etc with .
Is there a way for me to edit the contents of the Webview or to crop out some parts of the content, i'm focusing on UI and would like to clean up the content for a project i am working on.
Also lets say I want to display content of the webView individually as well (multiple webviews within an activity) for aesthetic purposes, how would I go about doing that?
One technique I've used in the past is to request the page with an HttpURLConnection rather than the WebView. Then I parse and edit the HTML data and display it in the WebView using the loadData method. You could even use something like JSoup to parse the HTML. However, if you are depending on having the JavaScript run on the page, you may have a problem because using loadData will disrupt the same-origin policy.
Can we embed our native Android components in between the normal HTML content and then render it on a webview?
For example, in a simple HTML page, if there is a button, I want to replace it with a Native Android Button.
How can we do that?
As far as I know, this is not possible with WebView (unless you split the HTML into multiple parts and render it in multiple WebViews with your button inserted inbetween, which may or may not work in your case).
Depending on the complexity of your HTML, you may want to consider this github project that renders HTML with native Android widgets: https://github.com/kobjects/htmlview
This might seem to you guys as a stupid question, but it comes into my mind so many times:
Why is there an ImageView in Android? We have a WebView, which is capable of displaying images, and so much more stuff. So why would you provide an ImageView as well? Maybe there is some fundamental reason for this, but I just don't see it. Whenever I want to use some media, I try to use a WebView, because this allows me to change the type of media if I wish to do so, and I do not need another Type of View.
So to not make this question to broad, let's bring it down to this:
In which scenario does an ImageView have big advantages over a WebView?
EDIT
And a second question:
If I have some audio, some html-text and some pictures, which are stored locally on my device, would I use one WebView to display them, or would I use one Type of View for each Type of media?
WebView is a much more expensive widget to use, in terms of memory consumption, than is ImageView.
The reason for the memory cost of WebView is the fact that WebView is powered by a fairly complete copy of WebKit. WebKit is an open source Web rendering engine that forms the heart of major Web browsers, such as Chrome and Safari. While the version of WebKit that lives in Android is one optimized for mobile use, it still represents a fairly substantial code base, and rendering complex Web pages takes up a fair amount of RAM (as anyone with lots of browser tabs on their desktop knows all too well).
FACT: The WebView implementation is such that it will consume more memory if used to download & display images. Always. Also, ImageView has special methods / XML tags for cropping, resizing, scaling & manipulating images (which WebView doesn`t).
A person has a image in the gallery. The persom wants to show it inside the app. What will it do?
Go and host it on an online image hosting website and then pass the url to the WebView?
That ain't a cool Idea.. and people and Google understand that.
Basically image view using for showing image from gallery , drawable or url.Webview for handling or showing web content or html kind of thing.
Well ImageView consumes less memory. ImageView can change the image display options.
ImageView can display images from different sources like "Resources, drawables".
WebView mainly for displaying html pages.
I came across the WebView class in android.webkit and was impressed by how it "does everything for you" (as a programmer), as far as rendering visual HTTP content on the screen.
My question: Is it possible to use the WebView class as a shortcut for parsing rendered HTML for non-visual purposes?
(that is, retrieve certain elements from a web page for text processing, etc.)
If so, how would one go about this?
You don't need to, as far as I know, Android is using TagSoup to parse HTML, and you can use it too.