使用水平滚动设置六边形形状

时间:2019-11-27 05:23:06

标签: kotlin scroll horizontal-scrolling

我正在尝试在水平滚动中设置六边形列表,但没有完成,如何解决?

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)
}

0 个答案:

没有答案