3

我有一个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 事件处理程序中获取项目的位置吗?

4

1 回答 1

1

您可以使用分隔页眉和页脚组件的自定义 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();
  }
}

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

于 2018-04-27T10:59:42.493 回答