Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically set the columnwidth in gridlayoutmanager

I am trying to do this using recycler view with gridlayoutmanager. GridLayoutmanager takes spancount. Here I want to update the view based on the width of the text in the recycler view items.

enter image description here

like image 656
Ranjana Dangol Avatar asked Nov 09 '16 04:11

Ranjana Dangol


People also ask

What is span count in the Grid layout?

Span count refers to the number of columns. This is fairly clunky and doesn't take into account larger screen sizes or screen orientation. One approach is to create multiple layouts for the various screen sizes.

What is use of GridLayout manager?

GridLayoutManager is used for displaying the data items in grid format and we can easily define the orientation for the items.

What is Grid LayoutManager in android?

Android GridLayoutManager is the RecyclerView. LayoutManager implementation to lay out items in a grid. In this tutorial, we'll create an application that displays CardViews inside a RecyclerView in the form of a GridLayout.


1 Answers

It's a late answer but I wanted to achieve exactly the same stuff!
Then after several hours of research, I found this lib (I don't know why I didn't find it earlier...) by Google: FlexboxLayout who has a FlexboxLayoutManager!

How to use:

val layoutManager = FlexboxLayoutManager(context)
layoutManager.flexDirection = FlexDirection.ROW
myRecyclerView.layoutManager = layoutManager

That's all!

like image 166
Itoun Avatar answered Oct 19 '22 08:10

Itoun