Home > Software design >  How to move items in a grid layout to center, if a row has less number of colums in android kotlin?
How to move items in a grid layout to center, if a row has less number of colums in android kotlin?

Time:12-15

enter image description here

This isn't a grid layout, I've used custom views to create this. Can anyone help me to create this with gridview . Does this even possible with GridLayout?

CodePudding user response:

You can can additional footer layout and pass other items to it.

CodePudding user response:

This might or might not be possible via GridLayoutManager, but there is no direct solution to get this using GridLayoutManager. I suggest you take a look at Flexbox layout manager here:

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

This is from Google and what you want can easily be done using it instead. You might need to play around with the properties a bit, but I think it can be done using the justifyContent property.

A rough code snippet would be something along the lines of

RecyclerView recyclerView = (RecyclerView) context.findViewById(R.id.recyclerview);
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(context);
layoutManager.setFlexDirection(FlexDirection.ROW);
layoutManager.setJustifyContent(JustifyContent.SPACE_AROUND);
recyclerView.setLayoutManager(layoutManager);
  • Related