I am not able to centre my VerticalGridView, while I was working with recyclerView it was fine

20 Views Asked by At

I am not able to centre my verticalGridView in xml, earlier I was using recyclerView which was perfectly centred based on the item count. But now after using gridview. It is getting aligned to topLeft side. I am ot preferring to set it using marginTop or start.

<androidx.leanback.widget.VerticalGridView
    android:id="@+id/deviceListRecyclerView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintHeight_default="wrap"
    app:layout_constraintHeight_max="@dimen/dp_249"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="@dimen/thumb_radius_3dp"
    android:background="@color/profile_screen_bg"
    android:nextFocusDown="@id/closeButton"
    app:focusOutEnd="true"
    app:focusOutFront="true"
    app:layout_constraintEnd_toEndOf="@id/close_btn_border"
    app:layout_constraintStart_toStartOf="@id/close_btn_border"
    app:layout_constraintBottom_toTopOf="@id/close_btn_border"
    app:layout_constraintTop_toBottomOf="@id/subTitleTextView"
    tools:listitem="@layout/item_device" />

My entire layout is constraint and gravity is set to centre

I tried wrapping it inside another linear layout, by adding margin left it is working but i prefer other way

0

There are 0 best solutions below