Span multiple columns with RecyclerView

浪子不回头ぞ 提交于 2019-11-28 15:43:13

Currently, StaggeredGridLayoutManager only supports views that span all the columns (for a vertically configured layout), and not an arbitrary number of them.

If you still want to span them across all the columns, you should do this in the adapter implementation:

public final void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

    StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) viewHolder.itemView.getLayoutParams();
    layoutParams.setFullSpan(true);
}

IMHO, StaggeredGridLayoutManager is still under heavy development and Google wants us to use it for feedback :(

What I did to span all columns for a vertically configured layout was create new LayoutParams and set full span to true in the adapter implementation:

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, int position) {

    StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    layoutParams.setFullSpan(true);
    viewHolder.itemView.setLayoutParams(layoutParams);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!