像Instagram搜索一样实现非对称网格布局管理器 [英] Implement Asymmetrical Grid Layout Manager Like Instagram Search

查看:131
本文介绍了像Instagram搜索一样实现非对称网格布局管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个RecyclerView并将我的适配器的layoutManager设置为GridLayout. 但我想要GridLayout像Instagram搜索一样,如下图所示,

I Created a RecyclerView And Set layoutManager Of My Adapter To GridLayout . But I Want GridLayout Like Instagram Search below image,

我想要这样的GridView:

请帮助我.谢谢 .

我尝试了SpanSizeLookup,但是我仍然遇到问题,并且我无法控制我的项目以这种方式进行布局. .

i tried SpanSizeLookup But i Have Still My Problem And i Cant Control My Items to laying out exactly that way . . .

推荐答案

请看一下这个答案

并在跨度"中显示您的列表

and for show Your list in Span

val manager = SpannedGridLayoutManager(object : SpannedGridLayoutManager.GridSpanLookup{
        override fun getSpanInfo(position: Int): SpannedGridLayoutManager.SpanInfo {
            // Conditions for 2x2 items
            return if (position % 12 == 0 || position % 12 == 7) {
                SpannedGridLayoutManager.SpanInfo(2, 2)
            } else {
                SpannedGridLayoutManager.SpanInfo(1, 1)
            }
        }

    },3/*column*/,1f/*how big is default item*/)

    binding.feedHome.setHasFixedSize(true)
    binding.feedHome.layoutManager = manager
    binding.feedHome.adapter = adapter

此图像帮助您如何计算显示大图像中的项目

and this image help you how to calculate item in show big image

这篇关于像Instagram搜索一样实现非对称网格布局管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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