I have a txt file which is around 2MB. I need to display it in android. I have tried out WebView and it takes around 5 seconds to load and display the file. Is there any way I can get it rendered faster? Moreover, I dont want to load all the text at the start. Something like a scrollbar which displays elements efficiently is what I require. I need not stick to WebView alone, but can choose to show it using any efficient way.
You can divide your text by paragraphs and use listview. show each paragraph of text in one item.
Related
I have an activity that gets data from a web service. The output of the web service consists of multiple sets of one web URL and some text. The URL points to an image. Each set is displayed by creating a linear layout which contains an imageview and textview. So, for 200 sets, I would have 200 layouts, 200 imageviews, and 200 textiews. I know that a list view would be a better solution, but I've gone too far in the project to change this now.
Currently, I download all images before the activity is displayed. I download around 200 images and in the future this might rise to more than 1000.
I would like to download the images only when the imageview appears on screen. The approach I am thinking of is creating some listener or event so that once the the imageview or layout appears on screen, the download starts. I searched a lot for this but could not find a good solution. My problem is creating the listener not starting the download.
Some solutions suggested lazy load but this would still mean all images are loaded which would not be appropriate for users who have limited download capacity.
Edit: I do not want to load all images, only the ones that appear on screen. And every time the user scrolls, the new imageview that appear on screen also start downloading.
I ended up using a different and easier approach by following #Akos's solution on this link for detecting the end of the scroll view. Once the activity starts, I load 10 layouts. Once the scroll view reaches the end, I display a progress dialog and load 10 more layouts.
Now I need to decide what widgets to use. There are a brief text description from an SQLite database and an image from an SD card or from the Internet on the screen.
I think that it would be better to use a single WebView to show the content than a TextView, an ImageView, and a TextView again. Are there any better ideas?
Here is a picture I created on Lucidchart.
Using WebView is not a good idea, Put the three components within a RelativeLayout and in a ScrollBar so that you can extend the elements without worrying about the size of the text as well as image size. And also webView will not render text perfectly.
Either option is fine. If the text in the database is in html format, you should use a webview. If not, you can use two textviews and one imageview.
With the WebView: you can justify the text, but it will not be a very clean solution if you want to resize the image for different screen sizes/resolutions.
I'm writing one of those reader applications. I would like to know if you have opinions and arguments for and against using WebView and Canvas (with drawText()) to achieve it.
What are the requirements:
format text according to a few html tags: <p>, <strong>, <h3>, <br/>, <a>,
display images within the text (they are in <img> tags),
display the text in two columns on tablet devices,
paging the text (Google currents style)
The ones in bold are absolutely required. The latter are strongly desired, but I can drop them.
So as far as my knowledge goes:
WebView will be great when it comes to displaying the html formatted text. I also don't have to take care of loading images, tey will be loaded automatically with <img> tags (will they, even if I use loadData() instead of loadUrl()?). The problems begin if I try to page the text. Is there a possibility to count the size of the text in a WebView and reflow it into multiple pages (using ViewPager)?
Canvas is great when it comes to counting the size of the text, putting it into columns and pages. But I will have to handle all the HTML tags myself, format the text myself. What is even worse, I will have to extract images' urls, handle the downloading and putting them back to the text (reflowing the whole text every time they load). Am I right?
Can you point some other advantages and disadvantages of using them? Which would you choose? Or maybe something else? Or is there some lib which does at least some of the work for me?
Why not use the Textview combined with spanned text and viewpagers for the paging.
First let me say that I'm very new to android development (although I have a good understanding of the basics of java), and I am building a magazine reader app for a campus publication I work for.
I want to display each article using a ViewPager widget. I'm going to build a java program which enables the magazine editor to post articles in .txt format onto a server, along with images associated with each, and have the android app periodically download these articles to a local folder.
I'm a little confused about how to construct the views for each ViewPager from the text files. Somehow my logic needs to determine the size of the screen running the app, in order to know how many words can fit on each screen.
Is this right, or am I fundamentally misunderstanding ViewPager somehow? If so, how might I structure the program to configure the views dynamically based on the txt + images given to it?
From what I understand, each page will contain as much of the article as possible, and when the user selects the article they will be able to see the entire thing. Something like this, but so it fills up the entire screen?
If this is the case, you have two options here:
Just ellipsize the textview so that it ends with a "..." at the end. Probably the preferred solution.
Resize the TextView to fit all your text (Auto Scale TextView Text to Fit within Bounds).
EDIT:
Here's a different interpretation of your question.
From what I understand, you're trying to have something like an eBook reader with an undefined number of pages; kind of what Flipboard does:
Basically, once all the text fills in the entire area you want to have it continue to the next page.
The easiest way to do this, if you do not need native performance, would be to just use a WebView, split the text across several columns, and have only one column be visible at a time.
However, it is certainly possible to calculate how tall the entire text would be and then split it up accordingly; i.e. Pagination in Android TextView
It seems similar questions have been asked and addressed: Splitting a TextView into multiple TextViews relative to screen height (see the accepted answer).
what I want is exactly what ThinkFree Office pdf viewer Reading View does.
I have a bunch of text and I want to be able to adjust it's size (users can choose from different zooms) and the text should paginate accordingly, I want it to wrap the screen, so that the user doesn't have to 'move' the screen, the rest of the text will show on the next page.
I know how pagination works, but how can I determine how much text has fitted the screen, so I know what to show on the next page?
Thank you
I mean't that you could adapt the codebase there by turning off the resizing part and just using it to paginate. It definitely would need work to make it fit this problem. Did you find a solution?