我有一个RecyclerCollectionComponent
,我使用DataDiffSection
提供数据。现在我想为第一个和最后一个项目留出一些余量(比如说d 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事件处理程序中获取项目的位置?
答案 0 :(得分: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();
}
}
现在,您可以为页眉/页脚/正文组件配置不同的页边距。