Android EpoxyRecyclerView-切换方向

问题描述 投票:0回答:1

我正在尝试使用环氧树脂构建以下布局结构:

enter image description here

前三个布局来自EpoxyAModel。第四个来自EpoxyBModel。

这是我的buildModels函数:

override fun buildModels() {

    aModels.forEach { //this happens 3 times
        modelA {
            id("someID")
            (...)

        }
    }

    modelB {
        id("someID2")
        (...)
    }

}

通过此设置,我得到以下结果:

enter image description here

这是可以理解的,因为EpoxyRecyclerView的文档说:

如果RecyclerView设置为match_parent大小,则滚动方向设置为垂直,setHasFixedSize设置为true。

如果高度设置为wrap_content,则滚动方向为设置为水平,并且对于轮播,setClipToPadding设置为false用法。

我的问题是:是否有可能获得理想的效果,还是必须定义另一个EpoxyRecyclerView和控制器?

谢谢。

android android-recyclerview epoxy
1个回答
0
投票

好吧,我知道了!

首先,我们需要将GridLayoutManager分配给EpoxyRecyclerView

recyclerView.layoutManager = GridLayoutManager(context, 3)

然后,在EpoxyBModel内部,我们需要重写getSpanSize方法以告知布局管理器此元素与整行项目一样大:

override fun getSpanSize(totalSpanCount: Int, position: Int, itemCount: Int): Int = 3
© www.soinside.com 2019 - 2024. All rights reserved.