0

I want to place two layouts containing RecyclerViews side by side, so that they have the same width and fill their parents, i.e. each one should have 50% of its parent's layout width.

Usually you set layout_weight for that, but layout_weight does not work with RecyclerViews on old devices. If layout_weight is set, it stops recycling and just creates all views for all items at once, which is too slow, especially on old devices.

What are the alternatives?

I use Jetpack 1.1.0. Perhaps the issue has been fixed in 1.2.0?

Is there some other layout xml attribute for half-width?

Do not use the xml layout and set layoutparams in code to screen width / 2?

Change the item count, so that the adapter only has the visible items, and somehow new items are added, when the user scrolls down in the view?

BeniBela
  • 16,412
  • 4
  • 45
  • 52
  • 1
    you can setup a guideline at 50% and constraint the RecyclerViews to it – Stachu Aug 06 '20 at 15:09
  • with the androidx.constraintlayout package? That might work. But I have not included that library in my app. It might be overkill to add a new dependency for this issue – BeniBela Aug 06 '20 at 16:20
  • After trying various layout settings, I might have found one that does not have problems. `android:layout_width="10dp"` rather than `android:layout_width="0dp"` on the first child with layout_weight – BeniBela Aug 06 '20 at 18:23

0 Answers0