reactjs - react native如何排列卡片形成网格视图?
问题描述
我想以应该形成网格视图的方式排列卡片。我尝试了几个网格视图组件,但我无法导航到数据中的每个项目npm install react-native-super-grid
。所以我想用CardSection
我的拥有。但我不知道如何将其排列在每行 2 张卡片中。以下是我的 CardSection 代码
卡片部分
const CardSection = (props) =>{
return(
<View style={styles.containerStyle}>
{props.children}
</View>
);
};
const styles ={
containerStyle: {
padding: 10,
backgroundColor: 'white',
borderWidth:0,
marginBottom:10,
marginLeft:10,
marginRight:10,
borderColor:'#808080',
marginTop:50,
elevation: 10,
flexDirection:'row',
flexWrap:'wrap'
}
};
我现在尝试的只是列出卡片如下
列表
<CardSection>
<TouchableOpacity onPress={() => Actions.newworkRequest()}>
<Text>New Work Request</Text>
</TouchableOpacity>
</CardSection>
<CardSection>
<TouchableOpacity onPress={() => Actions.workerDetails()}>
<Text>Worker</Text>
</TouchableOpacity>
</CardSection>
<CardSection>
<TouchableOpacity onPress={() => Actions.reportViewing()}>
<Text> Reports</Text>
</TouchableOpacity>
</CardSection>
<CardSection>
<TouchableOpacity onPress={() => Actions.compltpage()}>
<Text> Complaints</Text>
</TouchableOpacity>
</CardSection>
<CardSection>
<TouchableOpacity onPress={() => Actions.userpage()}>
<Text> Users</Text>
</TouchableOpacity>
</CardSection>
如何将其设为网格视图?这样连续两张卡。请帮助。这就是我现在得到的 https://i.stack.imgur.com/vtnuv.png 。我试图给FlexDirection:row
,但所有的卡都会进来同一行。所以我删除了它。请帮我解决问题。
解决方案
您必须在所有这些卡片部分的父级上应用这些样式。
const styles ={
mainContainer: {
flex: 1,
flexWrap: 'wrap',
flexDirection: 'row'
},
containerStyle: {
padding: 10,
backgroundColor: 'white',
borderWidth:0,
marginBottom:10,
marginLeft:10,
marginRight:10,
borderColor:'#808080',
marginTop:50,
elevation: 10
}
}
列表
<View style={styles.mainContainer}>
<CardSection style={styles.containerStyle} />
...
</View>
推荐阅读
- python - 迭代熊猫框架失败
- c# - C#如何获取变量的实际较大的正负数
- google-sheets - 用于检查 A 列是否为空白或 D 列是否为“TRUE”的 Google Sheets Arrayformula 插入消息列 E
- python - update_or_create django 管理员导入
- h.264 - AAC & AVC 字节流数据到 ts 文件
- tensorflow - Tensorboard:通过迭代/步骤过滤直方图
- debugging - 如何找出软件挂起的原因?(qemu + zephyr + tfm 的问题)
- xml - 使用 XML conf 文件更改 powershell 脚本中的目录
- javascript - 如何调用另一个函数来更改 Highcharts 股票中的时间范围选择器和日期选择器?
- java - JPA:在保存父母时重复孩子