Android 如何处理RecyclerCollectionComponent项目之间的空间

Android 如何处理RecyclerCollectionComponent项目之间的空间,android,litho,Android,Litho,我有一个RecyclerCollectionComponent,我使用DataDiffSection提供数据。现在,我想为第一个和最后一个项目留一些余量(比如x dp),并在项目之间留一些余量(比如y dp) 我的onRender如下所示: @OnEvent(RenderEvent::class) fun onRender( c: ComponentContext, @FromEvent model: SomeObject): Render

我有一个
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,该GroupSection用于分隔页眉和页脚组件

@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();
  }
}
现在,您可以为页眉/页脚/正文组件配置不同的页边距