简体   繁体   English

Android EpoxyRecyclerView - 切换方向

[英]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.

相关问题 在Android中切换方向 - Switching orientation in Android 切换方向时保存Android片段的状态 - Saving the state of Android fragment while switching the orientation Android方向传感器-完全关闭方向传感器 - Android orientation sensor - switching off the orientation sensor completely Android-从纵向/横向切换方向会将属性重置为默认设置 - Android - Switching orientation from portrait/landscape resets attributes to default settings 切换标签页和方向时Android应用程序丢失状态 - Android App Losing State When Switching Tabs And Orientation 切换到横向方向很慢 - Switching to landscape orientation is slow Android屏幕方向使用不同的xml(切换/旋转屏幕横向和纵向) - Android screen orientation use different xmls (switching/rotating screen landscape and portrait) 使用使用计时器的Android应用程序切换方向时,如何保持原始计时器处于活动状态? - When Switching Orientation with an Android App that uses a Timer, how to I keep the original timer active? 方向android - orientation android Android - 切换到相同方向时调用“onConfigurationChanged()”(即横向反转横向) - Android - “onConfigurationChanged()” not called when switching to same orientation (i.e landscape to reverse landscape))
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM