我创建了一个Recyclerview,如下图所示 如何管理?
答案 0 :(得分:0)
将此添加到singlerow.xml的根布局:
android:layout_marginBottom="10dp"
<强>更新强>
垂直间距ItemDecoration
扩展ItemDecoration,添加自定义构造函数,将空间高度作为参数并覆盖getItemOffsets()方法:
public class VerticalSpaceItemDecoration extends RecyclerView.ItemDecoration {
private final int verticalSpaceHeight;
public VerticalSpaceItemDecoration(int verticalSpaceHeight) {
this.verticalSpaceHeight = verticalSpaceHeight;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
outRect.bottom = verticalSpaceHeight;
}
}
如果您不想在最后一项下方插入空格,请添加以下条件:
if (parent.getChildAdapterPosition(view) != parent.getAdapter().getItemCount() - 1) {
outRect.bottom = verticalSpaceHeight;
}
注意:您还可以修改outRect.top,outRect.left和outRect.right属性以获得所需的效果。