【发布时间】:2019-04-12 19:23:41
【问题描述】:
我正在尝试创建一个水平的FlatList,它周围有一些间距。我能够使用列表中的paddingLeft 正确地获得开始间距,但列表中的paddingRight 似乎没有在其后放置任何空格(如果我一直滚动到最后,则按下最后一项正对着边界)。
这是一个 Snack,您可以运行并现场试用:https://snack.expo.io/@saadq/aW50cm
这是我的代码:
import * as React from 'react';
import { Text, View, FlatList, StyleSheet } from 'react-native';
const data = [{ key: 1 }, { key: 2 }, { key: 3 }, { key: 4 }];
class App extends React.Component {
render() {
return (
<View style={styles.container}>
<FlatList
style={styles.flatList}
horizontal
data={data}
renderItem={() => (
<View style={styles.box}>
<Text>Box</Text>
</View>
)}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
flatList: {
marginTop: 100,
paddingLeft: 15,
paddingRight: 15, // THIS DOESN'T SEEM TO BE WORKING
// marginRight: 15 I can't use marginRight because it cuts off the box with whitespace
},
box: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: 50,
width: 100,
borderWidth: 1,
borderColor: 'black',
paddingHorizontal: 15,
marginRight: 15,
},
});
export default App;
使用marginRight 而不是paddingRight 似乎确实给出了预期的间距结果,但是它会导致一个不同的问题,即空白始终存在并在滚动时切断项目。任何帮助将不胜感激!
【问题讨论】:
标签: react-native flexbox react-native-flatlist react-native-flexbox