jun*_*lin 6 javascript flexbox reactjs react-native react-native-flexbox
如何实现如下图所示的正方形布局?
或者有相关的包存在吗?
小智 4
我使用 ScrollView 和 flexbox 的组合来实现我的静态网格视图。
import {Dimensions} from 'react-native';
....
return (
<ScrollView>
<View style={styles.container}>
{
this.props.categories.map((category, index) => {
return (
<TouchableOpacity
key={index}
style={styles.item}
onPress={() => {}}
>
<Image
style={styles.itemIcon}
source="..."
/>
<Text style={styles.itemTitle}>
{category.name}
</Text>
</TouchableOpacity>
)
})
}
</View>
</ScrollView>
)
var styles = StyleSheet.create({
container: {
flexDirection: 'row',
flexWrap: 'wrap'
},
item: {
width: Dimensions.get('window').width * 0.5,
height: 100,
borderWidth: 1,
borderColor: "lightgray",
alignItems: 'center',
justifyContent: 'center'
},
itemIcon: {
width: 100,
height: 100,
resizeMode: 'contain'
},
itemTitle: {
marginTop: 16,
},
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7476 次 |
| 最近记录: |