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.
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!
Related
have anyone done the same layout as fig. 1? i am currently using StaggeredGridLayoutManager but the result is fig 2. could anyone help me regarding this?
Ps tried using grid layout but it just copy the height of the largest height
Use GridLayoutManager instead of StaggeredGridLayoutManager for achieving same layout as fig. 1
GridLayoutManager creates the equal height grids.
val gridLayoutManager = GridLayoutManager(this, 2)
recyclerview.layoutManager = gridLayoutManager
I have some tags (Array of String), when I use a recyclerView or listView it only accept Vertical, Horizontal or Grid arrangements, but I need to implement it like chip group lazy arrangement, how do I do that,
Like this
chipGroup
Thanks
I recommend Google's flexbox-layout library for this. It provides a FlexboxLayoutManager for use with RecyclerView:
val layoutManager = FlexboxLayoutManager(context).apply {
setFlexDirection(FlexDirection.ROW)
}
context.findViewById<RecyclerView>(R.id.recyclerview).setLayoutManager(layoutManager)
Is it possible to show multiple text in a recycler view/carousel view in android/kotlin.If yes,then what would be the logic for that or what topic should I read that will help me with this.
I have attached a example diagram below.I want to create the below part,there is some other layout on top :
Really need some help over here.
Yes, I believe you're looking for a StaggeredGridLayoutManager for RecyclerView.
For example, when setting up your RecyclerView, set your LayoutManager to a new StaggeredGridLayoutManager.
// get the reference of RecyclerView
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
// set a StaggeredGridLayoutManager with 3 number of columns and vertical orientation
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(staggeredGridLayoutManager); // set LayoutManager to RecyclerView
A more in-depth example could be found here, https://abhiandroid.com/materialdesign/recyclerview-as-staggered-grid-example.html.
I am working on a tag structure currently and to display that I have used Staggeredgrid layout manager of Recyclerview to get the required result as below image:
But when I used StaggeredGrid, It is providing result as below:
My code to display adapter in Recyclerview is as given below:
val staggeredGridLayoutManager = StaggeredGridLayoutManager(2, LinearLayoutManager.VERTICAL)
rvTags.layoutManager = staggeredGridLayoutManager
rvTags.adapter = AllergyAdapter(tags)
On increasing the span count to 3, all the items are contracting.
I want that if "Peanut butter" is big enough then only 1 item should come in 1 row and if "neem, garlic and soy" can fit in 1 row, then it should fit.
Basically, I need a way to dynamic span count according to the content size.
Any help will be appreciated.
The suggested answer is not working because it is counting span count for whole of Recyclerview and Not particular row wise.
Either you can go with the dynamic spinning or what you can do is get the help of libraries.
Please check URL for tags libraries.
Tags Views
Here is a most suitable view: ChipView
With custom layouts : ChipView
And for dynamic column binding, you can use AsymmetricGridView.
URL : AsymmetricGridView
I came across such a requirement and ideally, a Flexbox should be a good option to try.
layoutManager=new StaggeredGridLayoutManager(4, LinearLayoutManager.HORIZONTAL);
hi i want to make a recycler view to take items horizontal as many as the screen fit but with vertical scroll like this image as example
I try with StaggeredGridLayoutManager but it must specify the number of column want the column take as screen size any help will be good
You can use FlexLayoutManager for this kind of design FlexLayout
Here is a example snippet to use FlexLayoutManager in RecycleView
RecyclerView recyclerView = (RecyclerView) context.findViewById(R.id.recyclerview);
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(context);
layoutManager.setFlexDirection(FlexDirection.COLUMN);
layoutManager.setJustifyContent(JustifyContent.FLEX_END);
recyclerView.setLayoutManager(layoutManager);
Their are many attributes to use FlexLayout Go through the documents on github
As Burhanuddin Rashid commented, you should use the FlexBoxLayout. It has a LayoutManager for RecyclerViews, so the additional code will be minimal.
https://github.com/google/flexbox-layout#flexboxlayoutmanager-within-recyclerview