3
我正在嘗試使用FlatList向網格格式的某個人顯示一堆用戶頭像,但最終看起來很奇怪,我似乎無法弄清楚如何解決此問題。FlatList numColumns看起來不能正常工作?
這裏是我的FlatList代碼如下所示:
<FlatList
style={{flex: 1}}
data={this.props.usersList}
horizontal={false}
numColumns={3}
columnWrapperStyle={{ marginTop: 10 }}
renderItem={({ item }) => this.renderItem(item)}
keyExtractor={this._keyExtractor}/>
和這裏的成分是什麼樣子的renderItem:
class UserButton extends React.Component {
render() {
const { item, onPress } = this.props;
return (
<TouchableOpacity style={styles.button} onPress={onPress}>
<Image
source={(item.avatar) ? { uri: item.avatar } : require('../assets/images/userplaceholder.png')}
resizeMode='cover'
style={styles.imageStyle}
/>
</TouchableOpacity>
)
}
const styles = {
button: {
height: 100,
width: 100,
borderColor: '#aaa',
backgroundColor: '#aaa',
borderWidth: 2,
borderRadius: 50,
justifyContent: 'center',
alignItems: 'center',
marginHorizontal: 5,
},
imageStyle: {
height: 96,
width: 96,
alignSelf: 'center',
borderRadius: 48,
marginTop: (Platform.OS == 'android') ? 0 : 0.4
}
}
export default UserButton;
人有什麼想法?