Margin/padding in last Child in RecyclerView

前端 未结 9 1152
醉话见心
醉话见心 2021-01-30 05:56

I\'m trying to add Padding/Margin Bottom in the last row and Padding/Margin Top in the first row. I can not do it in the item xml as it would affect all of my Children.

I

9条回答
  •  情书的邮戳
    2021-01-30 06:33

    I use this in kotlin

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder(view), position: Int) {
        if (position == itemsList.lastIndex){
            val params = holder.itemView.layoutParams as FrameLayout.LayoutParams
            params.bottomMargin = 100
            holder.itemView.layoutParams = params
        }else{
            val params = holder.itemView.layoutParams as RecyclerView.LayoutParams
            params.bottomMargin = 0
            holder.itemView.layoutParams = params
        }
      //other codes ...
    }
    

提交回复
热议问题