Android Staggered Gridview Layout - android

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

Related

How to create a horizontal list view or recycler view with fixed size by changing the width of its items

I'm beginner in Android Development and trying to create a display of items in such a way that the size of these varieties according to the quantity, as they have done in this app. Any suggestions?
Screenshot 1
Screenshot 2
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager​.​HORIZONTAL​, false);
RecyclerView myList = (RecyclerView) findViewById​(​R​.​id​.​my_recycler_view​);
myList​.​setLayoutManager​(​layoutManager​);
So according to your question you have to add weight to the child elements which you can be given from parent layout like ex: recyclerview weight 3, and its item weight 1 each(if you have 3 items and fit in the width with margins on either sides) and consider to assign 3 to 6 elements in the width of the screen with horizontal scrolling
mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true));
check here how to set weights for the views How to set layout_weight attribute dynamically from code?

Show multiple text labels in a Horizontal recycler view/carousel view

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.

Recycler view with wrap content items horizontal and vertical scroll

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

Recyclerview with rows and columns?

Is it possible to have RecyclerView look like a grid? I.e. look like a 3x3 matrix?
The orientation can be only HORIZONTAL or VERTICAL. In iOS I can have UICollectionView have sections and rows. What about RecyclerView in Android?
Yes that is possible. You just need to replace your LinearLayoutManager with GridLayoutManager.
Before setting the adapter you need to set following lines
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getActivity(), int_value(of no of items to be in one row);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setAdapter(myAdapter);
It will show int_value no of elements in one row.For a square grid(3x3), you will have to give 9 items to the adapter.

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.
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!

Categories

Resources