gpt4 book ai didi

css - 在列之间 react Native FlatList 分隔符

转载 作者:技术小花猫 更新时间:2023-10-29 10:22:50 28 4
gpt4 key购买 nike

我有一个包含多个列的 FlatList:

    <FlatList
numColumns={4}
ItemSeparatorComponent={this.renderSeparator}
...
</FlatList>

还有一个行分隔符:

  renderSeparator = () => (
<View
style={{
backgroundColor: 'red',
height: 0.5,
}}
/>
);

但是分隔符只出现在行之间,而不是列之间(即使我添加了 width: 0.5

View on expo

最佳答案

您可以在 renderItems 中添加 if else 条件并检查索引模数以添加分隔符。我只使用这个,一切都很好。

类似于:-

_renderItem = ({item,index}) => {
return(
<View style={[{ backgroundColor: 'red', flex: 1 }, index%2==0 ? { marginRight: 10 } : { marginLeft: 10 } ]}>
<Text>{item.key}</Text>
</View>
)
}

希望对您有所帮助。

关于css - 在列之间 react Native FlatList 分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45580034/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com