我有一个包含多个列的 FlatList:
<FlatList
numColumns={4}
ItemSeparatorComponent={this.renderSeparator}
...
</FlatList>
还有一个行分隔符:
renderSeparator = () => (
<View
style={{
backgroundColor: 'red',
height: 0.5,
}}
/>
);
但是分隔符只出现在行之间,而不是列之间(即使我添加了 width: 0.5
最佳答案
您可以在 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/