RecyclerView项目超出了保证金范围

时间:2018-07-01 16:57:51

标签: android android-layout android-recyclerview android-constraintlayout

我有一个RecyclerView,其中包含4个项目,并且clipToPadding设置为false

我为两个页边距都设置了50dp,并且为backgroundColor正确设置了页边距,但是RecyclerView的项目超出了RecyclerView的范围。

<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>

这是要演示的图像 enter image description here

黑色背景是父ConstraintLayout,绿色背景是为recyclerView设置的颜色,白色/蓝色项目是ViewHolders。

我在此图像中有一个自定义LayoutManager,但该错误也发生在默认的LinearLayoutManager中。

你知道是什么原因吗?

1 个答案:

答案 0 :(得分:1)

当您在父级布局中将clipChildren设置为true时,会发生此错误。

删除该行,它应该可以解决您的错误。

相关问题