3

I'm trying to display an article with paragraphs, images, quotes, etc. My backend currently returns an article as a list of paragraphs, images, etc. but this can be changed if needed.

I tried the following :

  • Using a WebView and loading the whole article. Works fine but WebViews are very consuming and I can't customize content appearance as I would like to.

  • Using a ScrollView and populating it with TextViews for each paragraph and ImageViews for each image. Works OK but is very laggy at the beginning while populating the ScrollView

  • Using a ListView (and later a RecyclerView) to benefit from recycling. The problem with this solution is that some items may be quite long (ie : a long paragraphe) and it can be laggy when a long item appears on screen while scrolling.

None of the solutions above seems to be optimal, so I wonder : what's the best way to display an article?

Thanks for your answers

Edit 2: All the solutions above work, my question is not about how to make it work but about how to make it as optimized and smooth as possible.

Edit: This is the kind of things I'm trying to display.

enter image description here

Community
  • 1
  • 1
MathieuMaree
  • 7,453
  • 6
  • 26
  • 31
  • 2
    I would still recommend going for RecyclerView, you will just have to truncate long articles and add the details screen for the whole article – Chaosit Jul 29 '15 at 10:23
  • @Chaosit I'm not talking about a list of articles but about the content of one single article! – MathieuMaree Jul 29 '15 at 10:26
  • I'm sorry I've misunderstood the question, in this case if it is possible to isolate separate parts of article (like "chapters") I would use two-level RecyclerView - top level will contain the name of the section and after user clicks on the name field - you should expand the content part of the section – Chaosit Jul 29 '15 at 10:34
  • 1
    If such isolation is impossible the only solution I can see is a WebView – Chaosit Jul 29 '15 at 10:35
  • 1
    ok, now I can see the screenshot of what you want to show, I still think that WebView is better to show such long pages, the problem is that mobile apps are usually not designed for displaying such long pages. Alternative solution I can think of is using the ViewPager (or some paginated vertically scrolled element), but in this case you will have to figure out how to add pagination to the article - and it looks like it's possible to do that – Chaosit Jul 29 '15 at 10:56
  • @Chaosit Thanks. I like your solution with the `ViewPager`, it could definitely make everything smoother. Unfortunately, I think reading an article with this kind of vertical pagination is not as comfortable as a regular `ListView`/`ScrollView`... If you have another solution, I'll take it! – MathieuMaree Jul 29 '15 at 11:05
  • sorry that was my last idea =), perhaps the use of your own custom subclassed `ScrollView` implementing rendering of additional views as soon as user scrolls for instance 75% of current scroll distance may work, but in this case the scrollbar will behave really weird from user's point of view(like reaching 75% of distance and then jumping back to 50) – Chaosit Jul 29 '15 at 12:43
  • use the method Html.fromHtml(String , ImageGetter, TagHandler), this way you can use an html like string to display a well formatted article inside a single TextView – Daniel Mendel Sep 29 '15 at 17:16

1 Answers1

1

RecyclerView is the best practice. It has the best optimization.