使用 RecyclerView 跨越多列 [英] Span multiple columns with RecyclerView

查看:45
本文介绍了使用 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.

我将 RecyclerView.Adapter 与 StaggeredGridLayoutManager 一起使用.它似乎不是开箱即用的功能.我想我可以制作一个自定义布局管理器,只是不知道从哪里开始.我试过搜索,但找不到任何关于如何让项目跨越多列的信息.

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 仍在大量开发中,Google 希望我们将其用于反馈:(

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

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

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