小编Ste*_*ner的帖子

FlatList numColumns似乎无法正常工作?

我正在尝试使用FlatList以网格格式向用户显示一堆用户头像,但最终看起来非常奇怪,我似乎无法弄清楚该如何解决。

这是它的样子

这是我的FlatList代码的样子:

<FlatList
style={{flex: 1}}
data={this.props.usersList}
horizontal={false}
numColumns={3}
columnWrapperStyle={{ marginTop: 10 }}
renderItem={({ item }) => this.renderItem(item)}
keyExtractor={this._keyExtractor}/>
Run Code Online (Sandbox Code Playgroud)

这是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: …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-flatlist

3
推荐指数
2
解决办法
9711
查看次数