0

I have an activity with a scrollable view. I also have containers that all have the same structure - consist of imageButton and also several textViews that serve as a description. The whole thing looks like that:

image

The problem is that there are around 30 elements with the same structure and when each one of them has so many textViews I get the warning -

Layout has more than 80 views, bad for performance.

The reason why I have so many views is because of the different formatting of the different words. How would it be possible to reduce the views and still get the same formatting?

P.S. I already read that how to resolve "Layout has more than 80 views, bad for performance"? . But this doesn't help me, since all the information that I have, should be static and always visible.

Devil10
  • 1,853
  • 1
  • 18
  • 22
ladyeli555
  • 59
  • 6
  • Why are you using a scrollview and not a listview? – tyczj Jul 23 '18 at 20:55
  • @tyczj What difference would that make when I still have the textviews? – ladyeli555 Jul 23 '18 at 21:07
  • TextViews can contain images as compound drawables. No need for extra ImageViews. – Phantômaxx Jul 23 '18 at 21:15
  • use recyclerView instead of using different separate views. – Devil10 Jul 24 '18 at 04:06
  • It is helpful if you can show how you are getting the **DATA** in _**API**_. so we could look for better responsive layout or view – Abhinav Suman Jul 24 '18 at 08:21
  • @ladyeli555 beause you wont have more than 80 views. a row in a recyclerview will only contain the minimum amount of views needed for each row (lets just say 10 views in this case). A row in your example would contain an imageview and some text views. A new row is created for each item in the list and far more efficient than having it all in a scollview – tyczj Jul 24 '18 at 13:43
  • Thank you very much for all your comments! – ladyeli555 Jul 25 '18 at 23:11

2 Answers2

2

You will want to set up your layout using a RecyclerView.

If your app needs to display a scrolling list of elements based on large data sets (or data that frequently changes), you should use RecyclerView.

Android Developer Guide has some pretty good documentation on how to set this up. Also, here is a video tutorial on RecyclerView by SlideNerd. He has a pretty good series for android developers.

J. Jefferson
  • 980
  • 8
  • 12
0

In addition to what J. Jefferson said about RecyclerView. As you mentioned in your initial post:

The reason why I have so many views is because of the different formatting of the different words. How would it be possible to reduce the views and still get the same formatting?

You can do different text formatting without creating a separate textview. Have a look at the following https://stackoverflow.com/a/41953808/8312634

N0000B
  • 409
  • 1
  • 7
  • 16