Implement Asymmetrical Grid Layout Manager Like Instagram Search

我只是一个虾纸丫 提交于 2021-02-07 04:29:15

问题


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

I Want A GridView Like This :

Please Help Me . Thanks .

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


回答1:


please take a look this answer

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



来源:https://stackoverflow.com/questions/56680985/implement-asymmetrical-grid-layout-manager-like-instagram-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!