[英]Android EpoxyRecyclerView - switching orientation
I am trying to build the following layout structure with Epoxy:我正在尝试使用 Epoxy 构建以下布局结构:
First three layouts are from EpoxyAModel.前三个布局来自 EpoxyAModel。 The fourth one is from the EpoxyBModel.
第四个来自 EpoxyBModel。
This is my buildModels function:这是我的 buildModels 函数:
override fun buildModels() {
aModels.forEach { //this happens 3 times
modelA {
id("someID")
(...)
}
}
modelB {
id("someID2")
(...)
}
}
With this set up I am getting the following result:通过此设置,我得到以下结果:
This is understandable, since the documentation of EpoxyRecyclerView
says:这是可以理解的,因为
EpoxyRecyclerView
的文档说:
If the RecyclerView is set to match_parent size then the scrolling orientation is set to vertical and setHasFixedSize is set to true.
如果 RecyclerView 设置为 match_parent 大小,则滚动方向设置为垂直,setHasFixedSize 设置为 true。
If the height is set to wrap_content then the scrolling orientation is set to horizontal, and setClipToPadding is set to false for carousel usage.
如果高度设置为 wrap_content 则滚动方向设置为水平,并且 setClipToPadding 设置为 false 以用于轮播。
My question is: is there a possibility of getting the desired effect or do I have to define another EpoxyRecyclerView
and controller?我的问题是:是否有可能获得所需的效果,或者我是否必须定义另一个
EpoxyRecyclerView
和控制器?
Thanks in advance.提前致谢。
Okay, I figured it out!好吧,我想通了!
Firstly, we need to assign a GridLayoutManager
to the EpoxyRecyclerView
:首先,我们需要为
EpoxyRecyclerView
分配一个GridLayoutManager
:
recyclerView.layoutManager = GridLayoutManager(context, 3)
Then, inside the EpoxyBModel
we need to override the getSpanSize
method to tell the layout manager that this element is as big as a whole row of items:然后,在
EpoxyBModel
我们需要覆盖getSpanSize
方法来告诉布局管理器这个元素和一整行项目一样大:
override fun getSpanSize(totalSpanCount: Int, position: Int, itemCount: Int): Int = 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.