React Native 基本控件的使用(1)

前端之家收集整理的这篇文章主要介绍了React Native 基本控件的使用(1)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_301_0@

1、View

最简单的给组件设定尺寸的方式就是在样式中指定固定的width和height。React Native中的尺寸都是无单位的,表示的是与设备像素密度无关的逻辑像素点。

写法一:

 <View> <View style={{width: 50,height: 50,backgroundColor: 'powderblue'}} /> <View style={{width: 100,height: 100,backgroundColor: 'skyblue'}} /> <View style={{width: 150,height: 150,backgroundColor: 'steelblue'}} /> </View>

写法二:

<View>
   <View style={styles.wid5} />
   <View style={styles.wid10} />
   <View style={styles.wid15} />
</View>
const styles = StyleSheet.create({ wid5:{ width: 50,height: 50,backgroundColor: 'powderblue' },wid10:{ width: 100,height: 100,backgroundColor: 'skyblue' },wid15:{ width: 150,height: 150,backgroundColor: 'steelblue' } });

效果图如下:

<View style={{flex: 1}}> <View style={{flex: 1,backgroundColor: 'powderblue'}} /> <View style={{flex: 2,backgroundColor: 'skyblue'}} /> <View style={{flex: 3,backgroundColor: 'steelblue'}} /> </View>

效果图:

flexDirection:

//`flexDirection`:`column`看看 <View style={{flex: 1,flexDirection: 'row'}}> <View style={{width: 50,backgroundColor: 'powderblue'}} /> <View style={{width: 50,backgroundColor: 'skyblue'}} /> <View style={{width: 50,backgroundColor: 'steelblue'}} /> </View> 

效果图:

2、

原文链接:https://www.f2er.com/react/304988.html

猜你在找的React相关文章