跨多个列RecyclerView [英] Span multiple columns with RecyclerView

查看:429
本文介绍了跨多个列RecyclerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我试图去是有一个交错的布局,但在列表中的第一个项目需要跨越两列。前两行也有固定的高度。我拥有了一切工作,除了第一项跨两列。

So what I am trying to go for is having a staggered layout but the first item in the list needs to span two columns. The first two rows are also a fixed height. I have everything working except the first item spanning two columns.

我现在用的StaggeredGridLayoutManager的RecyclerView.Adapter。似乎并不像它的开箱即用的功能。我想我可以做一个自定义布局管理器,我只是不知道从哪里开始。我试图寻找,但我找不到有关如何获取项目可以跨越多个列的任何东西。

I am using the RecyclerView.Adapter with the StaggeredGridLayoutManager. Doesn't seem like it is out of the box functionality. I assume I can make a custom layout manager I'm just not sure where to start. I have tried searching but I can't find anything about how to get items to span multiple columns.

下面的图片是什么,我在寻找在列表中。

The image below is what what I am looking for in the list.

推荐答案

目前, StaggeredGridLayoutManager 仅支持跨所有列(在垂直配置的布局)的看法,不是任意数量的人。

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

恕我直言, StaggeredGridLayoutManager 仍处于重发展,谷歌希望我们使用它的反馈:(

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

这篇关于跨多个列RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆