我能够在RecyclerView
:
this.recyclerView.layoutManager = layoutManager
val dividerItemDecoration = DividerItemDecoration(this.recyclerView.context, layoutManager.orientation)
this.recyclerView.addItemDecoration(dividerItemDecoration)
结果如下:
如何在第一个单元格的顶部添加一行?
答案 0 :(得分:0)
首先,您不应在页眉和项目/页脚和项目之间创建相同的分隔符。如果可以选择,用户会感到困惑。为了获得良好的用户界面,我建议在页眉/页脚上制作彩色背景。像这样:
如果您坚持在标题中添加分隔符,则可以在ItemDecoration上编辑它,就像项目分隔符一样。将此分隔符用于标题项目装饰。更多详细信息,请访问DividerItemDecoration
fun drawVertical(Canvas c, RecyclerView parent) {
val left = parent.getPaddingLeft()
val right = parent.getWidth() - parent.getPaddingRight()
val childCount = parent.getChildCount()
val child : View = parent.getChildAt(i)
val params : RecyclerView.LayoutParams = child.getLayoutParams();
val top = child.getBottom() + params.bottomMargin;
val bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}