נמרוד כהן
נמרוד כהן

Reputation: 108

RecyclerView items go out of margin bounds

I have a RecyclerView that has 4 items, and clipToPadding set to false

I have set 50dp for both margins, and the margin is enforced correctly for the backgroundColor, but the items of the RecyclerView are going out of the RecyclerView bounds.

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:background="#0F0"
    android:layout_marginStart="50dp"
    android:layout_marginEnd="50dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent">

</android.support.v7.widget.RecyclerView>

here is an image to demonstration enter image description here .

The black background is the parent ConstraintLayout, and the green background is the color set to the recyclerView, the white / blue items are the ViewHolders.

I have a custom LayoutManager in this image, but the bug occures with the default LinearLayoutManager as well.

Any idea what can be the cause?

Upvotes: 3

Views: 1462

Answers (1)

Vasili Fedotov
Vasili Fedotov

Reputation: 1171

This bug happens when you have clipChildren in your parent layout set to true.

delete the line and it should resolve your bug.

Upvotes: 6

Related Questions