0

I am following a tutorial on grid layout. In particular, I am replicating Suragch's answer.

The code itself is working fine, except I would like to center the RecyclerView in the activity.

I've tried

android:gravity="center"

and

android:layout_gravity="center"

on both the RelativeLayout AND RecyclerView, but neither works.

Also, I would like to eliminate the gaps between each column. Does anyone know how to go about doing this?

enter image description here

2 Answers2

0

Try android:layout_centerInParent=true into <RecyclerView>

Warrocker
  • 734
  • 6
  • 12
0

Depending on your parent Layout

If its RelativeLayout then

android:layout_centerHorizontal=true in RecyclerView

if its LinearLayout then

android:layout_gravity=center_horizontal in RecyclerView

One more interesting thing you can do in Adapter

the main parent Layout in adapter

try doing this

android:gravity=center_horizontal in main layout of adapter

bhuvnesh pattnaik
  • 1,365
  • 7
  • 14