android - 如何处理 RecyclerCollectionComponent 的项目之间的空间

标签 android litho

我有一个 RecyclerCollectionComponent,我在其中使用 DataDiffSection 提供数据。现在我想为第一个和最后一个项目留出一些边距(比如 x dp),并在项目之间留出一些边距(比如 y dp)。

我的 onRender 看起来像这样:

@OnEvent(RenderEvent::class)
    fun onRender(
            c: ComponentContext,
            @FromEvent model: SomeObject): RenderInfo {

        return ComponentRenderInfo.create()
                .component(MyAwesomeCoomponent
                        .create(c)
                        .someParam(param)
                        .build())
                .build()
    }

这只是创建一个并排放置的项目列表。如果我在此组件中包含边距,它将为所有项目提供相同的边距,而我希望第一个和最后一个项目的边距为 (x dp),中间项目之间的边距为 (y dp)。

有什么办法,我可以在 onRender 事件处理程序中获取项目的位置?

最佳答案

您可以使用分隔页眉和页脚组件的自定义 GroupSection 包装您的 DataDiffSection?

@GroupSectionSpec
public class YourGroupSectionSpec {
  @OnCreateChildren
  static Children onCreateChildren(SectionContext c) {
    return Children.create()
        .child(SingleComponentSection.create(c).component(header)...)
        .child(DataDiffSection.create(c)...)
        .child(SingleComponentSection.create(c).component(footer)...)
        .build();
  }
}

现在您可以为页眉/页脚/正文组件配置不同的边距。

关于android - 如何处理 RecyclerCollectionComponent 的项目之间的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49995222/

相关文章:

android - 恢复包含动态生成的 HTML 的 webview 状态

Android:有没有办法以编程方式打开关闭物理键盘?

java - 如何解析表格第三列的单元格?

android - Litho ListRecyclerConfiguration Kotlin 与 linearLayoutInfoFactory

android - FB 光刻 : How to set custom font for Text

java - 如何在 Android ListView 中显示评级栏?

android - Litho、ViewPager 和选项卡。如何使用 Litho 加载多个 Tab 的布局?

android - Android构建动态表单的解决方案

Android:如何使 Kotlin 中所有对象列表的类型转换器(用于 Room)通用