我开始学习 React Native,我正在尝试用图像创建 3 列的网格。我一直在使用numColumns
FlatList 的 prop 指定 3 列,然后设置 flex:1
对于我的图像,因此它们应该填充列的空间。然而flex:1
尝试 height:100,aspectRatio:1
时,我的图像都没有出现在列中显示我的所有图像。知道这是为什么吗?我的代码如下:
export default class ArtScrollView extends React.Component {
_renderItem = (item) =>
(
<Image style={styles.art} source={{uri:item.item.imgFilePath}}/>
)
render() {
return(
<FlatList numColumns={3}
data={Object.values(this.props.pods)}
renderItem={this._renderItem}/>
);
}
}
const styles = StyleSheet.create({
art:{
height:100,
aspectRatio:1,
//flex:1, <- Having this instead of specifying the height doesn't work
marginRight:10,
}
});
最佳答案
var {height, width} = Dimensions.get('window');
并将它们用作您的引用您的图像尺寸。 关于react-native - React Native - 在 FlatList 中使用 "flex",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47490772/