微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

React Native 基本控件的使用1

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.jb51.cc/react/304988.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐