简体   繁体   中英

Android Recyclerview for a few items

I have a list CardViews, each of which has a title and an icon. Upon clicking on each item, an Activity opens with that certain card's details.
I don't think I need more than a few items (I don't think more than 10), and I'm not sure how dynamic and changing they will be.

My question is: Should I use a RecyclerView to show these items, or should I just duplicate the cards and show them inside a LinearLayout without a RecyclerView ?

In terms of performance, which option is better?

Both options should be OK (I haven't tested the performance, but both run OK), although I would prefer the Linearlayout . Because the list is small, you lose most advantages of the RecyclerView (performance-wise).

If you decide to go with the LinearLayout , you could create a Compound control and reuse it for the different items so you don't have to edit every item manually if something changes.

And if you would decide to use the RecyclerView, don't forget to call setItemViewCacheSize() and set it to a reasonable amount (the count of your items), because for so few items it doesn't make sense to need to re-populate the items every time you scroll. It makes sense for bigger lists, where you can't effectively work with that many items, but for cca 10 items it seems faster if you cache them all. The next thing you should also do is call setHasFixedSize(true) on the RecyclerView. And if you don't need nested scrolling, call setNestedScrollingEnabled(false) too, otherwise the scrolling might behave a bit strange (no "fast/continued scrolling" if you swipe quickly).

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM