原文链接:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/react-native%E5%B8%83%E5%B1%80/

一、宽度和像素密度:

(1)首先你我们需要了解iPhone的各个尺寸:iphone 4s  3.5Screen、iphone 5    4Screen、iphone 6    4.7Screen、iphone 6 Plus 5.5 Screen

这个刚开始的时候对布局规划不是很好,没有考虑到兼容什么的,导致到最后浪费了好些时间(一般初学者都会忽略这些屏幕适配的问题)。

具体:var DimenSions=require('Dimensions');

var windowSize=Dimensions.get('window')

<View style={{width:windowSize.width,height:windowSize.height}}>

<Text>....</Text>

</View>

二、Flex的简单布局

(1)flex布局定义?

flex布局是flexible box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。

(2)适用条件:任何一个容器都可以指定为flex布局(比如你要做一个表格,那么就需要均等分配,这个时候你就可以使用flex布局)。

View style={styles.border1}>  

<View style={{flexDirection:'row',flex1,borderColor:'#e7e7e7',borderWidth:1}}>

<View style={{flex:1, justifyContent:'center', alignItems:'center',borderColor:'#e7e7e7',borderWidth:1}}>

<Text style={styles.color1}>缴费项目</Text>

</View>

<View style={{flex:1, justifyContent:'center',  alignItems:'center',borderColor:'#e7e7e7',borderWidth:1}}>

<Text style={styles.color1}>个人比例</Text>

</View>

<View style={{flex:1, justifyContent:'center', alignItems:'center',borderColor:'#e7e7e7',borderWidth:1}}>

<Text style={styles.color1}>公司比例</Text>

</View>

</View>

(3)flex中子布局与父布局的关系:子布局依赖与父布局

三、水平与垂直居中(alignItems、justifyContent)

<Text style={[styles.text, styles.header]}>

水平居中

</Text>

<View style={{height: 100, backgroundColor: '#333333', alignItems: 'center'}}>

<View style={{backgroundColor: '#fefefe', width: 30, height: 30, borderRadius: 15}}/>

</View>

<Text style={[styles.text, styles.header]}>

垂直居中

</Text>

<View style={{height: 100, backgroundColor: '#333333', justifyContent: 'center'}}>

<View style={{backgroundColor: '#fefefe', width: 30, height: 30, borderRadius: 15}}/>

</View>

<Text style={[styles.text, styles.header]}>

水平垂直居中

</Text>

<View style={{height: 100, backgroundColor: '#333333', alignItems: 'center', justifyContent: 'center'}}>

<View style={{backgroundColor: '#fefefe', width: 30, height: 30, borderRadius: 15}}/>

</View>

四、图片布局:

图片布局有一个stretchMode.通过Image.resizeMode进行访问

var keys=Objec.keys(Image.resizeMode).join('');

使用图片资源的两种方式

(1)使用本地的资源  <Image source={require('./my-icon.png')}> 但是有人也这样写

<Image source={require(images!my-icon.png)}>两者都可以。

(2)使用网络图片

<Image source={{uri:'图片的链接地址'}}>

可以通过设置图片的Style属性来对图片进行设置

var style=StyleSheet.create({

width:

height:

flex:

})

五、padding和margin

padding的语法结构:padding:10 , paddingLeft,paddingTop

margin的语法跟Padding一样;marginLeft:10,marginRight:10,marginTop

我们很多时候都在纠结于到底是用margin还是Padding,这两者之间有有什么区别:

1.padding 是属性定义的元素边框与元素之间的控件(指的是内边距)

2.margin指的是外边距

example:

(1)分别在文本上设置margin:10和padding:10:

<View style={styles.container}>

<View style={{width:100,height:200,borderColor:'black',borderWidth:1}}>

<Text style={{padding:10,borderColor:'red',borderWidth:1}}>设置Padding:10 </Text>

</View>

<View style={{width:100,height:200,borderColor:'black',borderWidth:1}}>

<Text style={{margin:10,borderColor:'red',borderWidth:1}}>设置margin:10 </Text>

</View>

</View>

(2)分别在View上设置margin:10和padding:10

<View style={styles.container}>

<View style={{padding:10,width:100,height:200,borderColor:'black',borderWidth:1}}>

<Text style={{borderColor:'red',borderWidth:1}}>设置Padding:10 </Text>

</View>

<View style={{margin:10,width:100,height:200,borderColor:'black',borderWidth:1}}>

<Text style={{borderColor:'red',borderWidth:1}}>设置margin:10 </Text>

</View>

</View>

react-native布局篇的更多相关文章

  1. 从web移动端布局到react native布局

    在web移动端通常会有这样的需求,实现上中下三栏布局(上下导航栏位置固定,中间部分内容超出可滚动),如下图所示: 实现方法如下: HTML结构: <div class='container'&g ...

  2. react native 布局注意点

    一.react native中很多是ES6语法. 1行.表示是js的严格模式. 'use strict';严格模式中变量必须先声明,然后赋值.定义等:还有就是this的绑定. 2行到8行.导入依赖,可 ...

  3. React Native布局

    一款好的APP离不了一个漂亮的布局,本文章将向大家分享React Native中的布局方式FlexBox. 在React Native中布局采用的是FleBox(弹性框)进行布局. FlexBox提供 ...

  4. React Native 入门篇

    React Native 英文官网:https://facebook.github.io/react-native/ React Native 中文官网:http://reactnative.cn/ ...

  5. React Native布局实践:开发京东client首页(三)——轮播图的实现

    上篇文章中,我们一起构建了京东client的TabBar.在本文中.将继续向大家介绍京东client首页轮播图及其下发功能button的开发方法,如今就让我们開始吧! 1.相关控件调研 眼下在Gith ...

  6. React Native布局详解

    Flexbox 布局 Flex有两个属性:Container  和 Item flex是Flexible Box的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性.采用fle ...

  7. React Native初探

    前言 很久之前就想研究React Native了,但是一直没有落地的机会,我一直认为一个技术要有落地的场景才有研究的意义,刚好最近迎来了新的APP,在可控的范围内,我们可以在上面做任何想做的事情. P ...

  8. React Native指南汇集了各类react-native学习资源、开源App和组件

    来自:https://github.com/ele828/react-native-guide React Native指南汇集了各类react-native学习资源.开源App和组件 React-N ...

  9. react native学习资料

    一:基础学习: react-native中文文档(react native中文网,人工翻译,官网完全同步)http://react-native.cn/docs/getting-started.htm ...

  10. React Native资料汇总

    React Native 官方文档中文版翻译 http://wiki.jikexueyuan.com/project/react-native/homepage.html REACT NATIVE开发 ...

随机推荐

  1. TOMCAT服务器配置域名

    最近做了个网站,用的是web'服务器是tomcat,框架式SpringMVC,功能做好后,就准备上线使用了, 手上已经有域名以及一台服务器,已经绑定好ip了,剩下的也就是配置Tomcat了,比较简单, ...

  2. 解决Jmeter插件ERROR: java.io.IOException: Agent is unreachable via TCP的错误

    今天在centos上搭建jmeter监控服务,服务正常启动,我点击run,就在一切看起来很美好的时候,报错了,ERROR: java.io.IOException: Agent is unreacha ...

  3. OracleOCP认证 之 Linux基础

    Linux 基础 一.SHELL 1: Shell 简介 shell 是用户和Linux 操作系统之间的接口.Linux 中有多种shell, 其中缺省使用的是bash. Linux 系统的shell ...

  4. OCM_第十一天课程:Section5 —》数据仓库

    注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...

  5. 温故而知新--JavaScript书摘(二)

    前言 毕业到入职腾讯已经差不多一年的时光了,接触了很多项目,也积累了很多实践经验,在处理问题的方式方法上有很大的提升.随着时间的增加,愈加发现基础知识的重要性,很多开发过程中遇到的问题都是由最基础的知 ...

  6. hdu3015树状数组 poj1990的离散化版本

    都是一类题目,推导调试比较烦,想出来还是不难的 /* 给定n个点对,按一维升序排序一次,每个点的序号为Di,按二维升序排序一次,每个点的序号为Hi 求sum{w(i,j)} w(i,j)=abs(Di ...

  7. 性能测试一:jmeter基础入门

    JMeter,一个100%的纯Java桌面应用,由Apache组织的开放源代码项目,它是功能和性能测试的工具.具有高可扩展性.支持Web(HTTP/HTTPS).SOAP.FTP.JAVA等多种协议的 ...

  8. Android SDK安装及配置模拟器

    环境搭建 1.安装JDK 2.下载Android sdk exe格式和zip格式都可以 3.安装installer_r24.4.1-windows.exe文件,里面有两个应用程序: "SDK ...

  9. HDU 1851 (N个BASH博弈子游戏)

    题意:n堆石子,分别有M1,M2,·······,Mn个石子,各堆分别最多取L1,L2,·····Ln个石头,两个人分别取,一次只能从一堆中取,取走最后一个石子的人获胜.后选的人获胜输出Yes,否则输 ...

  10. hdu 1385 Floyd 输出路径

    Floyd 输出路径 Sample Input50 3 22 -1 43 0 5 -1 -122 5 0 9 20-1 -1 9 0 44 -1 20 4 05 17 8 3 1 //收费1 3 // ...