Empty spaces at the end of row Recyclerview with GridLayoutManger - android

I am using recyclerview with gridlayoutmanger with spancount 2 containing fixed 12 elements only in recyclerview.On tablets in landscape mode the empty space is remaining after the sixth element. I want to fill the empty space with the elements from second row. If space is there than then first row contain either 6, 7, 8 ,9 ... elements depends upon the remaining space.

Use FlexLayoutManger with recycler view :
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);
See this link
https://github.com/google/flexbox-layout#flexboxlayoutmanager-within-recyclerview

Related

Android GridLayoutManager horizontal scroll with 3 items

I have recyclerview with GridLayoutManager and I want 2 things:
3 items in screen
horizontal scroll
Issue
If I don't use horizontal scroll I can have 3 items in screen but yeah it's not horizontal, but if I add horizontal option to GridLayoutManager then it does not show 3 items in screen row.
Current code that gives me 3 items in row (but it's vertical)
laundriesRecycler.layoutManager = GridLayoutManager(context, 3)
Testing code that gives me horizontal scroll but not 3 items in row
laundriesRecycler.layoutManager = GridLayoutManager(context, 3, GridLayoutManager.HORIZONTAL, false)
layoutManager code
laundriesRecycler.layoutManager = GridLayoutManager(context, 3)
laundriesRecycler.adapter = NearLaundriesAdapter(context, list, useraddress)

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?

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

set max rows 4 and columns to be dynamic in RecyclerView GridLayoutManager

I want a grid view which adds elements in new row each time when the row count reach 4 it should start adding element in 1st row.
Let say I have 7 items in 1st image and add 2 more elements then it should add first element at last index of 2nd column and second element at 1 index of column 3
Let say I have 11 items in 2nd image and add 2 more elements then it should add first element at last index of 3rd column and second element at 1 index of column 4
Try this:
GridLayoutManager layoutManager =
new GridLayoutManager(getActivity(), 4);
layoutManager.setOrientation(RecyclerView.HORIZONTAL);
recyclerView.setLayoutManager(layoutManager);
try this
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 4, GridLayoutManager.HORIZONTAL, false);
recycleView.setLayoutManager(gridLayoutManager);

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.

Categories

Resources