fli*_*lix 6 css grid-layout react-native
我想在 React Native 中创建网格中心菜单,我刚刚阅读了文档并且看起来不错,但是我在为每个网格菜单创建行时遇到了问题
我已经使用复制粘贴代码创建了 3x3 网格 flexbox:
<View style={{
flexDirection: 'row',
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<View>
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'powderblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'skyblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'steelblue'}} />
</View>
<View>
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'powderblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'skyblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'steelblue'}} />
</View>
<View>
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'powderblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'skyblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'steelblue'}} />
</View>
</View>
Run Code Online (Sandbox Code Playgroud)
结果如下:
但我需要为每个菜单添加一行,我的目标是创建一个菜单网格,如:
我已经完成了每个菜单的图标收集,并将用我的视图替换视图 Icon + Text
任何人都可以帮助我如何创建上面的菜单?
我将最后一种颜色更改为更明显,并将线条设置为“灰色”(您可以使用浅灰色或任何您想要的自定义颜色),以便您可以轻松更改它。
import {Dimensions, View} from 'react-native'
const DeviceWidth = Dimensions.get('window').width
Run Code Online (Sandbox Code Playgroud)
这是渲染函数中的代码:
<View style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<View style={{
flexDirection: 'row',
backgroundColor: "grey"}}>
<View>
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:1, backgroundColor: 'powderblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:1, backgroundColor: 'skyblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, backgroundColor: 'yellow'}} />
</View>
<View>
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:1, marginLeft:1, backgroundColor: 'powderblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:1, marginLeft:1, backgroundColor: 'skyblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginLeft:1, backgroundColor: 'yellow'}} />
</View>
<View>
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:1, marginLeft:1, backgroundColor: 'powderblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:1, marginLeft:1, backgroundColor: 'skyblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginLeft:1, backgroundColor: 'yellow'}} />
</View>
</View>
</View>
Run Code Online (Sandbox Code Playgroud)