添加部分的空间项目装饰

时间:2018-11-13 17:22:45

标签: android android-layout android-recyclerview

我用搜索结果除以其类型进行了recyclerview: 页眉,项目和页脚。我需要的是在这些部分之间添加空格(例如在卡片中),最好不要使用其他视图。

enter image description here

我试图在页眉本身上添加装饰,但是页边距错误

class SpaceHeaderDecoration(private val space: Int) : RecyclerView.ItemDecoration() {

override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
    ...

    val position = parent.getChildAdapterPosition(view)
    val viewType = parent.adapter.getItemViewType(position)
    if (viewType == Adapter.HEADER) {
        outRect.top = space
    }
  }
} 

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用DividerItemDecoration?:

c