dotGitignore
dotGitignore

Reputation: 1627

How to create a RecyclerView horizontal with a wrap_content width and not scrollable?

I want to achieve that my RecyclerView will display or add the item from left to right and when it reaches the end of the screen the added item will display on the next line like this.

enter image description here

and not like this

enter image description here

here is my code

<androidx.recyclerview.widget.RecyclerView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="11dp"
        android:layout_marginEnd="11dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        android:orientation="horizontal"
        tools:itemCount="10" />

I also tried using the StaggeredLayoutManager and Vertical orientation (Since as I said, I want to add the item from left to right) but using a Span I do not want to align the items like a Grid. Also the Column Count is not fix and it may be depends on the screen size.

any help is appreciated, Thank you!

Upvotes: 0

Views: 311

Answers (2)

Fabio
Fabio

Reputation: 2824

Documentation is a bit misleading, but I've used com.google.android.material.chip.ChipGroup successfully with a list of ViewSwitcher inside it. For the record it also worked with a list of MaterialButton.

It does have the UI behavior you want, but it's not related to RecyclerView so you have to do some coding if you're expecting the same API, I'd recommend extending your own MyWrappableView: ChipGroup.

Upvotes: 2

Ashok Gohel
Ashok Gohel

Reputation: 26

You can use FlexboxLayout.

Please follow the link.

https://github.com/google/flexbox-layout

Upvotes: 1

Related Questions