我正在尝试在水平滚动中设置六边形列表,但没有完成,如何解决?
override fun onBindViewHolder(holder: MyViewholder, position: Int) {
val pos = position + 1
val topMargin: Int = pxFromDp(holder.textView.getContext(), -17.toFloat())
val leftMargin: Int = pxFromDp(holder.textView.getContext(), 51.toFloat()) //3 times of 17
val param = holder.textView.getLayoutParams() as GridLayoutManager.LayoutParams
if (pos < 4) {
param.setMargins(0, 0, 0, 0)
} else if ((pos + 1) % 5 == 0 || pos % 5 == 0) {
param.setMargins(0, topMargin, 0, 0)
} else {
param.setMargins(0, topMargin, 0, 0)
}
holder.textView.setLayoutParams(param)
}