我有一个页面,其中包含2个不同的列表部分(listComponent1和listComponent2),在每个列表上方,我使用和创建了一个自定义标签,并将完整的部分保留在ScrollView中,现在我有一个要求,如果列表是每当我滚动2个标签(labelComponent1和labelComponent2)时,都应该停留在标题下方的顶部,即使列表项超出了视口。
我尝试在ScrollView组件内添加stickyHeaderIndices = {[1]}并显示了verticalVerticalScrollIndicator = {false}属性,但仍然无法正常工作,不确定我是否在做一些错误
代码:
<SafeAreaView>
<ScrollView alwaysBounceHorizontal={false} horizontal={false} contentContainerStyle={testStyle}>
{true && <View>
<labelComponent1 data={test1} />
<listComponent1 data={testData1} />
<Spacing />
<labelComponent2 data={test2} />
<listComponent2 data={testData2} />
</View >}
</ScrollView>
</SafeAreaView>
stickyHeaderIndices={[0]}
,因此第一个孩子会发粘。但不要将ScrollView
的子项包装在一个View
中。它将它们包装到一个组件中,因此ScrollView仅在子组件上具有。试试这个: