android-recyclerviewgridlayoutmanager

how to set items in GridLayoutManager fixed to start and end of parent with different span count


This is my RecyclerView :

<androidx.recyclerview.widget.RecyclerView
                android:id="@+id/add_transaction_pair_rec"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="23dp"
                android:overScrollMode="never"
                android:scrollbars="none"
                android:visibility="visible"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@+id/row_symbol_market_view_line"
                app:layout_constraintTop_toTopOf="parent"
                tools:itemCount="1"
                tools:listitem="@layout/row_add_transaction_rec_pair" />

This is my row layout :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/row_rec_pair_name_txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/sans_regular"
        android:paddingTop="@dimen/row_timeframe_mrg_tb"
        android:paddingBottom="@dimen/row_timeframe_mrg_tb"
        android:textAllCaps="true"
        android:textColor="@color/auth_blue_gray54"
        android:textSize="@dimen/symbol_ts" />

</LinearLayout>

I removed padding or marging from TextView in row layout, but it didn't work


Solution

  • i think making your row match parent and your text view gravity to center solves your problem.