Top Space to First Item in RecyclerView (TSFIR)


TSFIR:    SOLD




To add space to the first item of a RecyclerView, you can add padding to the RecyclerView itself and set clipToPadding to false so that the padding affects only the content and not the outer boundary.

Here's how it can be done in XML:

<android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        style="@style/WrapContent"
        android:layout_marginTop="16dp"     
        android:padding="16dp"
        android:clipToPadding = "false"
        app:layout_constraintTop_toBottomOf="@id/tvFoo"
        tools:layoutManager="android.support.v7.widget.GridLayoutManager"
        tools:listitem="@layout/item_foo"
        tools:orientation="horizontal"/>
 
In this configuration:
  • android:padding="16dp" adds padding inside the RecyclerView, giving spacing around the items.
  • android:clipToPadding="false" ensures that the padding doesn't affect the scrollable area, letting the first item appear with the padding space above it.

Post a Comment

Previous Next

نموذج الاتصال