我会在 recyclerView 的顶部和底部放置空白。
例如,在 html/css 中,我可以制作一个具有固定高度的可滚动父容器,并插入一个具有自适应高度的子容器,并设置子容器的 paddingTop 和 paddingBottom。
我尝试在layout.xml中重复这个系统
<ScrollView
android:id="@+id/ScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/RecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="50dp"
android:paddingBottom="35dp"
android:clipChildren="false"
android:nestedScrollingEnabled="false"
tools:itemCount="10" />
</ScrollView>
但我看到“wrap_content”仅在“match_parent”较小时才适应高度,因为 View 是可滚动的(理论上)(或者这就是我所理解的)。 但这会破坏我的系统,因为我需要子容器不可滚动。
如果我设置nestedScrollingEnabled =“false”
将元素从视口(viewport)中剪切出来,如果我设置“true”,则recycleView正常滚动但空白保持固定
是否存在另一种方式来获得我想要的东西?
最佳答案
尝试通过添加clipToPadding并设置为false来使用这种方式,您可以在顶部和底部添加空白
<android.support.v7.widget.RecyclerView
android:id="@+id/list_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/view_padding"
android:paddingRight="@dimen/view_padding"
android:clipToPadding="false"
android:paddingBottom="90dp"
android:paddingTop="90dp"/>
关于java - 如何在recyclerView的开始和结束处设置可滚动的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57340632/