我在RecyclerView中有2个列网格。我想对左栏中的项目使用不同的页边距,右栏中的项目使用不同的页边距。
类RecyclerView.Adapter的内部方法bindViewHolder(VH holder,int position),我怎么知道当前项目是在左侧还是右侧?
我尝试使用位置参数,但有时它会从右侧开始填充项目(下面的图片,查看第5项),所以没有用。
答案 0 :(得分:2)
您可以通过viewHolder的itemView获取列索引。
StaggeredGridLayoutManager.LayoutParams lp = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
int position = lp.getSpanIndex();
答案 1 :(得分:0)
我在RecyclerView中有2个列网格。我想用 左列中的项目的不同边距和不同的边距 右栏中的项目。
为paddings
使用不同的RecyclerView
怎么样?为padding
和paddingLeft
使用不同的paddingRight
值。