我有一个 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/