ReactNative之参照具体示例来看RN中的FlexBox布局

时间:2022-08-26 08:48:10

今天是重阳节,祝大家节日快乐,今天继续更新RN相关的博客。上篇博客《ReactNative之从HelloWorld中看环境搭建、组件封装、Props及State》中我们通过一个HelloWorld的一个示例介绍了RN的环境搭建、组件封装、Props以及States。经过这么多天,今天我们继续来看RN的东西,本篇博客是关于RN的Flex布局的,也就是说是关于RN中控件放哪儿的一篇博客。在RN中使用的是Flex布局,如果你之前接触过Web前端的话对FlexBox布局并不陌生,但是如果你之前没做过Web开发的话,也不影响看今天的博客。本篇博客也是RN开发的基础,算是比较重要的。

RN中控件的布局方式与Web前端开发中的div+css的盒式布局是极为相似的。本篇博客就来详细的讲解一下RN中的FlexBox布局,中文名“弹性布局”。RN中的FlexBox布局和CSS中的FlexBox大体相同,也是通过一些属性来控制控件的位置、大小以及各个控件之间的关系。在FlexBox中分为 容器属性(flexDirection、flexWrap、alignItems、justifyContent、alignContent)和 元素属性(flex、alignSelf、margin、padding、border、width、height等等)。顾名思义,容器属性是用来添加到 父组件上来控制子组件的位置的属性,而 元素属性则是添加到子组件本身控制本身的一种属性。稍后会详细介绍。

接下来我们将根据具代码来详细的介绍常用的几种FlexBox布局的属性,。根据常用性,下方会依次介绍RN中的Flex布局中的flex、flexDirection、justifyContent、alignContent、flexWrap、AlignItem、AlignSelf这些常用的属性。本篇博客所涉及的Demo会上传到博客最后方的github链接中。

先入为主,下方这个gif中所有的内容就是我们今天要结束的东西,全是关于Flex布局的。

  ReactNative之参照具体示例来看RN中的FlexBox布局

一、Flex

首先我们先来看一下flex的使用方式,flex属性接收的是一个number类型的值, 该值表示弹性布局的比例系数。具体的我们还要看一下下方关于Flex的一个Demo。

下方就是flex的具体使用方式,其中的flexValue是一个number类型的值。

<View style={{ flex: flexValue />

接下来我们来看一下flex具体的一个示例。我们通过点击来修改中间的flex的值来观察flex对每个view的影响:

  • 三个黑块中的初始的flex值为1, 所以三个黑色方块会平分屏幕。
  • 每点击一次,中间的黑块的flex数增加1,然后我们就看到中间黑块会增大,三个黑块的比例变成了1 :  2 : 1。每次点击都会有变化。

  ReactNative之参照具体示例来看RN中的FlexBox布局

最后我们来简单的看一下该效果的实现,代码如下。

  • 首先我们来看一下item的实现,Item即对应着每个黑块。这个item方法有个名为flexValue的参数,该参数用来接收设置的flex的值。所以在item中我们将flexValue指定给了View的flex属性。
  • 然后我们在看一下render中的实现。在Render中,我们添加了一个View来容纳item(黑块),View中三个item就对应着上述的三个黑块。中间的item的flex的值是从Status中获取的,下方会介绍到。
  • 最后我们在看一个ClickView这个方法,该方法会在点击View时执行,执行该方法时,我们为Status存储的flexValue自增了1。也就是说没点击 1 次中间的item的flex就会增加1。所以我们最终看到的效果是没点击一次,中间的黑块会增大。

  ReactNative之参照具体示例来看RN中的FlexBox布局

下方是上述示例的完整代码:

 // flex
import { Component } from "react";
import { TouchableOpacity, View, Text } from "react-native";
import React from "react"; type FlexStateType = {
flexValue: number
}
export default class FlexTestComponent extends Component<null, FlexStateType> {
flexValue = 1;
constructor(props) {
super(props);
this.state = {
flexValue: this.flexValue
};
} clickView = () => {
this.flexValue ++;
this.setState({flexValue: this.flexValue})
}; item = (flexValue: number) => {
return (
<View style={{ flex: flexValue, height: 50, backgroundColor: 'black', marginLeft:10, marginRight: 10 , justifyContent: 'center', alignItems:'center'}}>
<Text style = {{color: '#fff'}}>flex = {flexValue}</Text>
</View>
);
}; render () {
const {
flexValue
} = this.state;
return (
<TouchableOpacity onPress={this.clickView}>
<View style={{ height: 60, width: '100%', backgroundColor: '#e5e5e5', flexDirection: 'row' , alignItems: 'center'}}>
{this.item(1)}
{this.item(flexValue)}
{this.item(1)}
</View>
</TouchableOpacity>
);
}
}

二、FlexDirection

看完flex属性,接下来我们来看一下flexDirection属性。该属性在FlexBox布局中也是一个尤为重要而且比较常用的一个属性。flexDirection主要是用来控制子元素的布局方向的,主要分为横向布局和纵向布局,默认是纵向布局(column)。下方是flexDirection的属性值和使用方式。

属性值:

flexDirection?: "row" | "column" | "row-reverse" | "column-reverse";

用法示例:

<View style={{ flexDirection: 'row' />

flexDirection的属性值主要有以下几个:

  • row : '行',该值表示子元素自左向右横向排列, 。如下图的row, 先放的子元素1,如果有子元素2的话,会放到子元素1的右边,依次类推的横向布局。
  • row-reverse: '逆向的行',这个与row相反,该属性表示自右向左横向排列。具体参见下图中的row-reverse。
  • column:'列',该属性值表示子元素自上而下纵向排列,具体参见下方的column。
  • column-reverse: '逆向的列',这个与column相反,该属性则表示自下而上的纵向排列,具体参见下方的column-reverse。

  ReactNative之参照具体示例来看RN中的FlexBox布局

因该部分的demo对应的代码比较简单,介绍如下:

  • 首先我们封装了一个名为FlexDirectionTestView的视图,该视图对应着上述展示 1 2 3的视图。该视图对外留了一个属性,用来接收flexDirection。外边传入什么flexDirection的值,1 2 3这三个子视图就按什么排列。
  • 在FlexDirectionTestComponent组件中,我们就调用了FlexDirectionTestView这个视图,传入了不同的flexDirection属性,从而这个 1 2 3 子元素就会按照我们要求的样式去展示。

  ReactNative之参照具体示例来看RN中的FlexBox布局

完整代码示例:

 // flexDirection
import React, { Component } from 'react'
import { FlexStyle, StyleSheet, Text, View } from 'react-native' export default function FlexDirectionTestComponent () {
return (
<View style={{ height: 180, backgroundColor: '#c1c1c1' , flexDirection: 'row'}}>
<View style={{ height: '100%', width: '50%', justifyContent: 'space-around'}}>
<FlexDirectionTestView value={{ flexDirection: 'row' }}/>
<FlexDirectionTestView value={{ flexDirection: 'row-reverse' }}/>
</View> <View style={{ height: '100%', width: '50%', flexDirection: 'row' , justifyContent: 'space-around'}}>
<FlexDirectionTestView value={{ flexDirection: 'column' }}/>
<FlexDirectionTestView value={{ flexDirection: 'column-reverse' }}/>
</View>
</View>
)
} type FlexDirectionProps = {
value?: FlexStyle
} class FlexDirectionTestView extends Component<FlexDirectionProps> {
render () {
return (
<View style={[myStyle.flexDirectionProps, { flexDirection: this.props.value.flexDirection }]}>
<SubView value={'1'}/>
<SubView value={'2'}/>
<SubView value={'3'}/>
</View>
)
}
} type SubViewProps = {
value: string
}
class SubView extends Component<SubViewProps> {
render () {
return(
<View style={myStyle.subViewStyle}>
<Text style={{ color: 'white', fontSize: 17 }}> {this.props.value} </Text>
</View>
)
}
} const myStyle = StyleSheet.create({
subViewStyle: {
margin: 10,
borderRadius: 25,
width: 25,
height: 25,
backgroundColor: 'red',
justifyContent: 'center',
alignItems: 'center'
},
flexDirectionProps: {
backgroundColor: 'gray',
margin: 5
}
});

三、JustifyContent

今天这篇博客的干货还是比较足的,接下来我们来看一下第三个比较重要的属性justifyContent。该属性也是比较常用的,通常被用来控制子元素的左右方向的布局,这个与上面的flexDirection不同,justifyContent会控制整体子元素左右方向上的一个约束关系。下方是justifyContent的属性值和使用方式

属性值:

justifyContent?: "flex-start" | "flex-end" | "center" | "space-between" | "space-around" | "space-evenly"

用法示例:

<View style={{ justifyContent: 'flex-start' />

具体的还得看下方这个GIF图,该图中就列举了justifyContent所有的属性值,并且展示了每个属性值的不同表现形式,接下来详细的介绍一下每个属性值的作用。

  • flex-start: 该属性值的功能是让所有子元素靠左对齐,如下方点击flex-start的布局形式。
  • center: 则表示子元素在左右方向上居中展示,如下方点击Center按钮对应的布局形式。
  • flex-end: 这个与flex-start相反,flex-end则表示子元素靠右对齐,对应着下方点击flex-end按钮的布局形式。
  • space-between:从字面意思上不难看出,该属性值对应的是左右间距平分于子元素中间的布局方式,设置该属性值后,左右边上是子元素是紧贴父View的左右边距的,间距平分与子元素中间。
  • space-around: 该属性也是比较好理解的,就是左右间距环绕在子元素周围,从下方点击space-around的效果不难看出,设置该属性后,每个元素的左右边距是一致的,环绕在子元素之间。
  • space-evenly: 该属性值的意思是子元素的左右间距均分,这个间距包括子元素与子元素的间距,还包括子元素与父元素的间距。

  ReactNative之参照具体示例来看RN中的FlexBox布局

介绍完上述属性,我们来简单的看一下该示例的实现代码,从上述操作来看本部分的Demo会相对复杂一些。首先来看一下上述按钮区域对应的代码片段:

  • 首先我们定义了一个OperaView来容纳所有的点击的View,在该View中调用了我们自定义的customButton组件。
  • customButton组件接收一个参数,这个参数对应的就是justifyContent的属性值。每次点击该按钮,就会把按钮对应的属性值写入Status中。
  • 方法ClickView即为CustomButton点击时对应执行的方法。

  ReactNative之参照具体示例来看RN中的FlexBox布局

看完按钮区域的代码,接下来我们就来看一下布局区域的代码:

  • 首先来看一下Item,下方的item函数返回的就是布局区域的每个方框,每个方框的高度相同,宽度由参数决定。
  • 然后在看一下resultDisplayView, 该View函数对应的就是按钮下方的布局区域,该View的JustifyContent属性的值是直接从state中获取的。
  • 最后就来看一下render中了,在render中分别调用了按钮区和布局区两块的内容。

  ReactNative之参照具体示例来看RN中的FlexBox布局

完整代码如下:

 // justifyContent
import { Component } from "react";
import { Text, TouchableOpacity, View } from "react-native";
import React from "react"; type JustifyContentType = "flex-start" | "flex-end" | "center" | "space-between" | "space-around" | "space-evenly";
type JustifyContentCompontStateType = {
justifyContentValue: JustifyContentType
}
export default class JustifyContentTestComponent extends Component<null, JustifyContentCompontStateType> {
constructor(props) {
super(props);
this.state = {
justifyContentValue: 'flex-start'
};
} clickView = (value: JustifyContentType) => () => {
this.setState({ justifyContentValue: value});
}; customButton = (title: JustifyContentType) => {
return (
<TouchableOpacity onPress={this.clickView(title)}>
<View style = {{ width: 120, height: 30, backgroundColor: 'green', margin: 5, justifyContent:'center', alignItems:'center'}}>
<Text style={{color: '#fff', fontSize: 17}}>{title}</Text>
</View>
</TouchableOpacity>
);
}; operaView = () => {
return (
<View style={{
height: 90,
width: '100%',
justifyContent: 'center',
alignItems: 'center',
flexDirection:'row',
flexWrap:'wrap'}}>
{this.customButton('flex-start')}
{this.customButton('flex-end')}
{this.customButton('center')}
{this.customButton('space-between')}
{this.customButton('space-around')}
{this.customButton('space-evenly')}
</View>
);
}; item = (width: number) => {
return (
<View style = {{ height: 30, width: width, backgroundColor: 'green' , margin: 2}}/>
);
}; resultDisplayView = () => {
const {
justifyContentValue
} = this.state;
return (
<View style={{ height: 110, width: '100%', justifyContent: justifyContentValue, flexDirection: 'row', flexWrap:'wrap' }}>
{this.item(60)}
{this.item(100)}
{this.item(30)}
{this.item(80)}
{this.item(100)}
{this.item(90)}
{this.item(30)}
{this.item(80)}
</View>
);
}; render () {
return (
<View style={{ height: 200, backgroundColor: '#e5e5e5' }}>
{this.operaView()}
{this.resultDisplayView()}
</View>
);
}
}

四、AlignContent

接下来来看一下AlignContent这个属性及其相关的属性值。该属性与上面的JustifyContent属性的功能差不多,JustifyContent负责左右方向的子元素之间的关系,而AlignContent则负责上下方向上的子元素之间的布局。下方是AlignContent的相关属性值和使用方式:

属性值:

alignContent?:"flex-start" | "flex-end" | "center" | "stretch" | "space-between" | "space-around"

用法示例:

<View style={{ alignContent: 'flex-start' /> 

按照上述的思路,我们还是通过一个Demo来看一下每个属性值的具体的作用。下方就是本部分对应的Demo,每个按钮对应着AlignContent的一个属性值,点击相关按钮后,下方的子元素就会按照点击的按钮进行设置。下方是具体介绍:

  • flex-start: 子元素顶部对齐,点击下方的flex-start按钮会看到所有子元素向上对齐了。
  • center: 上下方向上居中,也就是说设置该属性,子元素会在上下方向上进行居中展示。
  • flex-end: 该属性与flex-start相反, 设置该属性,子元素会位于父元素的底部展示
  • space-between:间隔填充,子元素的上下间距位于子元素中间
  • space-around: 即间隔环绕在子元素的上下,与JustifyContent的space-around类似。
  • stretch:拉伸,该属性只有在子元素的高度没有设置的情况下适用,该情况下会自适应高度,以至填满父视图,具体如下所示:

  ReactNative之参照具体示例来看RN中的FlexBox布局

代码和之前的Demo的实现思路差不多,在此就不做过多赘述了,下方是该部分的完整示例:

 // alignItem
import { FlexAlignType, Text, TouchableOpacity, View } from "react-native";
import { Component } from "react";
import React from "react"; type AlignContentType = "flex-start" | "flex-end" | "center" | "stretch" | "space-between" | "space-around"; type AlignContentTestCompontStateType = {
alignContentValue: AlignContentType
}
export default class AlignContentTestComponent extends Component<null, AlignContentTestCompontStateType> {
constructor(props) {
super(props);
this.state = {
alignContentValue: 'flex-start'
};
} clickView = (title: AlignContentType) => () => {
this.setState({ alignContentValue: title});
}; customButton = (title: AlignContentType) => {
return (
<TouchableOpacity onPress={this.clickView(title)}>
<View style = {{ width: 120, height: 30, backgroundColor: 'green', margin: 5, justifyContent:'center', alignItems:'center'}}>
<Text style={{color: '#fff', fontSize: 17}}>{title}</Text>
</View>
</TouchableOpacity>
);
}; operaView = () => {
return (
<View style={{
height: '40%',
width: '100%',
justifyContent: 'center',
alignItems: 'center',
flexDirection:'row',
flexWrap:'wrap'}}>
{this.customButton('flex-start')}
{this.customButton('center')}
{this.customButton('flex-end')}
{this.customButton('space-between')}
{this.customButton('space-around')}
{this.customButton('stretch')}
</View>
);
}; item = (width: number, height: number) => {
return (
<View style = {{ height: height, width: width, backgroundColor: 'red' , margin: 2}}/>
);
}; resultDisplayView = () => {
const {
alignContentValue
} = this.state; let height = 30;
if (alignContentValue === 'stretch') {
height = -1;
}
return (
<View style={{ height: "60%", width: '100%', alignContent: alignContentValue, backgroundColor: '#efefef', flexDirection: 'row', flexWrap:'wrap'}}>
{this.item(50, height)}
{this.item(80, height)}
{this.item(30, height)}
{this.item(60, height)}
{this.item(50, height)}
{this.item(100, height)}
{this.item(30, height)}
{this.item(50, height)}
{this.item(80, height)}
{this.item(30, height)}
</View>
);
}; render () {
return (
<View style={{ height: 200, backgroundColor: '#e5e5e5'}}>
{this.operaView()}
{this.resultDisplayView()}
</View>
);
}
}

AlignContent

五、flexWrap

接下来看一下flexWrap这个属性,该属性负责折行的。例如当一个View没有设置flexWrap属性时,子元素又是横排的情况时,会在一行上一直往后排,并不会折行。如果想折行的话,那么就得使用这个flexWrap属性了,下方是flexWrap属性的相关值和用法:

属性值:

flexWrap?:"wrap" | "nowrap" | "wrap-reverse"

用法示例:

<View style={{ flexWrap: 'wrap' /> 

 

flexWrap的属性值比较少,也比较好理解,下方就进行简单的描述:

  • wrap: 折行,设置该属性意味着一行放不下时会自动换到下一行进行展示。
  • nowrap: 不这行,默认值,超出屏幕后也一直往一行后边叠加。
  • wrap-reverse: 逆向折行,这个虽然在查看类型的时候有这个选项,但是实测是不可用的,可忽略。

下方就是flexWrap所对应的Demo, 该Demo中的View就设置了flexWrap的属性为wrap的值,没点击一次我们就随机的往后边添加一个随机宽度的子View。从下方gif中不难看出,当最后一个View放不下时会自动的换到下一行进行展示。具体如下所示:

  ReactNative之参照具体示例来看RN中的FlexBox布局

该示例的完整代码:

 // flexWrap
import { Component } from "react";
import { TouchableOpacity, View } from "react-native";
import React from "react"; type FlexWrapTestComponentStateType = {
allViews: Array<any>
}
export default class FlexWrapTestComponent extends Component<null, FlexWrapTestComponentStateType> {
constructor(props) {
super(props);
this.state = {
allViews : [this.item()]
};
} clickView = () => {
let items = this.state.allViews;
items.push(this.item());
this.setState({allViews: items});
}; item = () => {
let randomWidth = Math.random() * 100 + 10;
return (
<View style={{backgroundColor: 'green', height: 30, width: randomWidth, margin: 5}} />
);
}; render () {
return (
<TouchableOpacity onPress={this.clickView}>
<View style={{ height: 100, backgroundColor: '#eaeaea' , flexDirection: 'row', flexWrap: 'wrap',}}>
{this.state.allViews}
</View>
</TouchableOpacity>
);
}
}

FlexWrap

  

六、AlignItem

该属性也是比较常用的,用来定义子元素在交叉轴上的对齐方式。也就是说,子元素是横向排列的,那么该属性就约定纵轴方向上的对齐方式。AlignItem属性的属性值也没几个,也比较好理解,下方是AlignItem对应的熟悉值和使用方式:

属性值:

type FlexAlignType = "flex-start" | "flex-end" | "center" | "stretch" | "baseline";

用法示例:

<View style={{ alignItem: 'flex-start' /> 

  

下方就是真的AlignItem实现的一个Demo, 我们将根据下方的Demo来具体的看一下AlignItem所对应的每个属性值的作用,具体如下所示:

  • flex-start: 首先还是来看一下flex-start, 下方我们的子元素是横向排列的,所以设置flex-start时,就意味着,子元素在纵轴开始的位置对齐,也就是顶部对齐。
  • center: 也是以横向排列的子元素为例,当设置alignItem为Center时,表示交叉轴方向上居中对齐,具体在该Demo中表现的是上下方向上居中对齐。
  • flex-end: 这个与flex-start相反,表示以交叉轴的尾部对齐。
  • baseline: 这个就比较有意思了,设置该属性值就意味着子元素以子元素中的文字的基线对齐

  ReactNative之参照具体示例来看RN中的FlexBox布局

该示例完整代码如下:

 // alignItem
import { FlexAlignType, Text, TouchableOpacity, View } from "react-native";
import { Component } from "react";
import React from "react"; type AlignItemTestCompontStateType = {
alignItemValue: FlexAlignType
}
export default class AlignItemTestComponent extends Component<null, AlignItemTestCompontStateType> {
constructor(props) {
super(props);
this.state = {
alignItemValue: 'flex-start'
};
} clickView = (title: FlexAlignType) => () => {
this.setState({ alignItemValue: title});
}; customButton = (title: FlexAlignType) => {
return (
<TouchableOpacity onPress={this.clickView(title)}>
<View style = {{ width: 80, height: 30, backgroundColor: 'red', margin: 5, justifyContent:'center', alignItems:'center'}}>
<Text style={{color: '#fff', fontSize: 17}}>{title}</Text>
</View>
</TouchableOpacity>
);
}; operaView = () => {
return (
<View style={{ height: '100%', width: '30%', backgroundColor: '#e0e0e0', justifyContent: 'center', alignItems: 'center'
}}>
{this.customButton('flex-start')}
{this.customButton('center')}
{this.customButton('flex-end')}
{this.customButton('stretch')}
{this.customButton('baseline')}
</View>
);
}; item = (height: number, fontSize: number) => {
return (
<View style = {{ height: height, width: 50, backgroundColor: 'red' , margin: 10 }}>
<Text style={{fontSize: fontSize}}> {fontSize} </Text>
</View>
);
}; resultDisplayView = () => {
const {
alignItemValue
} = this.state; let heights = [100, 150, 80];
if (alignItemValue === 'stretch') {
heights = [-1, -1, -1];
}
return (
<View style={{ height: '100%', width: '70%', alignItems: alignItemValue, backgroundColor: '#efefef', flexDirection: 'row', justifyContent: 'center' }}>
{this.item(heights[0], 10)}
{this.item(heights[1], 20)}
{this.item(heights[2], 30)}
</View>
);
}; render () {
return (
<View style={{ height: 200, backgroundColor: '#e5e5e5' , flexDirection: 'row'}}>
{this.operaView()}
{this.resultDisplayView()}
</View>
);
}
}

AlignItem

七、AlignSelf

最后我们来看一下这个AlignSelf属性,该属性是元素属性,主要设置在子元素上,用来控制单个子元素在父元素的交叉轴的位置。AlignSelf的作用方式与AlignItem差不多,只不过一个作用于父元素,一个是作用于子元素。下方是AlignSelf的属性值和用法示例:

属性值:

type FlexAlignType = "flex-start" | "flex-end" | "center" | "stretch" | "baseline";
type AlignSelfType = "auto" | FlexAlignType; 

用法示例:

<View/> 
  <View style={{ alignSelf: 'flex-start' /> 
</View> 

最后我们仍然通过一个Demo来看一下AlignSelf的表现形式。在下方Demo中我们依次为右边中间的黑块设置的AlignSelf属性。每个属性的值的意思可参见AlignItem的属性值,只不过这些属性值是作用于子元素的。具体关于AlignSelf的内容就不做过多赘述了。

  ReactNative之参照具体示例来看RN中的FlexBox布局

该部分Demo完整示例:

 // alignSelf
import { FlexAlignType, Text, TouchableOpacity, View } from "react-native";
import { Component } from "react";
import React from "react"; type AlignSelfTestCompontStateType = {
alignItemValue: FlexAlignType
}
export default class AlignSelfTestComponent extends Component<null, AlignSelfTestCompontStateType> {
constructor(props) {
super(props);
this.state = {
alignItemValue: 'flex-start'
};
} clickView = (title: FlexAlignType) => () => {
this.setState({ alignItemValue: title});
}; customButton = (title: FlexAlignType) => {
return (
<TouchableOpacity onPress={this.clickView(title)}>
<View style = {{ width: 80, height: 30, backgroundColor: 'black', margin: 5, justifyContent:'center', alignItems:'center'}}>
<Text style={{color: '#fff', fontSize: 17}}>{title}</Text>
</View>
</TouchableOpacity>
);
}; operaView = () => {
return (
<View style={{ height: '100%', width: '30%', backgroundColor: '#e0e0e0', justifyContent: 'center', alignItems: 'center'
}}>
{this.customButton('flex-start')}
{this.customButton('center')}
{this.customButton('flex-end')}
{this.customButton('stretch')}
</View>
);
}; resultDisplayView = () => {
const {
alignItemValue
} = this.state; let height = 80;
if (alignItemValue === 'stretch') {
height = -1
}
return (
<View style={{ height: '100%', width: '70%', alignItems: 'flex-start', backgroundColor: '#efefef', flexDirection: 'row', justifyContent: 'center' }}>
<View style = {{ height: 150, width: 50, backgroundColor: 'black' , margin: 10}}/>
<View style = {{alignSelf: alignItemValue, height: height, width: 50, backgroundColor: 'black' , margin: 10}}/>
<View style = {{ height: 100, width: 50, backgroundColor: 'black' , margin: 10}}/>
</View>
);
}; render () {
return (
<View style={{ height: 180, backgroundColor: '#e5e5e5' , flexDirection: 'row'}}>
{this.operaView()}
{this.resultDisplayView()}
</View>
);
}
}

AlignSelf

经过本篇博客的详细介绍想必对FlexBox有了更详细的了解,掌握了上述属性后,在RN中写布局应该就不是什么难事儿了。当然本篇博客值介绍了FlexBox布局比较核心的部分,想什么Margin、Padding等等这些属性比较简单,就不做过多赘述了。本篇博客所涉及的所有Demo会在github上给出,下方会给出相关链接。

下篇博客会集中根据具体示例来聊一下RN中常用的动画。

github地址:https://github.com/lizelu/ReactNativeTestDemo

ReactNative之参照具体示例来看RN中的FlexBox布局的更多相关文章

  1. ReactNative之结合具体示例来看RN中的的Timing动画

    今天继续更新RN相关的博客.上篇博客详细的聊了RN中关于Flex布局的相关东西,具体请参见<ReactNative之参照具体示例来看RN中的FlexBox布局>.本篇博客继续更新RN的动画 ...

  2. ReactNative之从&OpenCurlyDoubleQuote;拉皮条”来看RN中的Spring动画

    上篇博客我们聊了RN中关于Timing的动画,详情请参见于<ReactNative之结合具体示例来看RN中的的Timing动画>本篇博客我们将从一个“拉皮条”的一个动画说起,然后来看一下R ...

  3. 三分钟学会CSS3中的FLEXBOX布局

    原文地址,保护版权,请勿转载:http://page.factj.com/blog/p/2574 这篇文章里我们将学习CSS里flexbox布局的几个最重要的概念,通过学习flexbox布局,你会发现 ...

  4. CSS3弹性伸缩布局(中)——flexbox布局

    混合过渡版 上一篇我们主要讲了旧版box布局,今天这篇主要讲flexbox布局. 混合版本的Flexbox模型是2011年提出的工作草案,主要是针对IE10浏览器实现的伸缩布局效果,其功能和旧版本的功 ...

  5. react-native热更新从零到成功中的各种坑

    https://github.com/reactnativecn/react-native-pushy/blob/master/docs/guide.md Android NDK暂时没有安装 在你的项 ...

  6. 通过实现仿照FeignClient框架原理的示例来看清FeignClient的本质

    前言 FeignClient的实现原理网上一搜一大把,此处我就不详细再说明,比如:Feign原理 (图解) - 疯狂创客圈 - 博客园 (cnblogs.com),而且关于FeignClient的使用 ...

  7. zigbee学习&colon;示例程序SampleApp中按键工作流程

    zigbee学习:示例程序SampleApp中按键工作流程 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN7 开发环境:IAR8. ...

  8. zigbee学习&colon;示例程序SampleApp中通讯流程

    zigbee学习:示例程序SampleApp中通讯流程 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 参考链接: http://wjf88223.bl ...

  9. 安卓图表引擎AChartEngine&lpar;四&rpar; - 源码示例 嵌入Acitivity中的折线图

    前面几篇博客中都是调用ChartFactory.get***Intent()方法,本节讲的内容调用ChartFactory.get***View()方法,这个方法调用的结果可以嵌入到任何一个Activ ...

随机推荐

  1. 购物车界面,不同section,点击增减物品,确定取消选中的逻辑判断

    1.首先在自定义的cell中,创建两个代理方法 @protocol shopCartDelegate <NSObject> -(void)shopCartDelegate:(ShopCar ...

  2. design the relations

    Computer Science An Overview _J. Glenn *shear _11th Edition A pivotal step in designing a relati ...

  3. linux云计算集群架构学习笔记&colon;rhel7基本命令操作

     1-3-RHEL7基本命令操作 1.1Linux终端介绍 Shell提示符 Bash Shell基本语法. 1.2基本命令的使用:ls.pwd.cd. 1.3查看系统和BIOS硬件时间. 1.4 L ...

  4. Yii2 behavior运用

    class ReturnDataTypeBehaviors extends Behavior { public $type = 'json'; public $pcOrMobile = 'pc'; / ...

  5. 完美逆向百度手机助手5&period;0底部菜单栏 - Android Tabhost 点击动画

    先看看百度手机助手5.0的样子: 发现他是用一个CustomTabHost.java来实现底部TabHost点击效果的,很漂亮,点击Tab的时候文字会上跑,图片会从底部跑出来的一个小动画. 下面我用自 ...

  6. Nginx中的信号量&lpar;信号控制&rpar;

  7. Oracle ADDM报告生成和性能分析

    我写的SQL调优专栏:https://blog.csdn.net/u014427391/article/category/8679315 对于局部的,比如某个页面列表sql,我们可以使用Oracle的 ...

  8. matplotlib图例-【老鱼学matplotlib】

    图例是啥,直接上图就知道了: 怎么创建上面的图例呢? 很简单,首先在plt.plot()函数中设置label文本属性,然后调用plt.legend()生成图例就可以了,完整的代码如下: import ...

  9. EventFlow&period;helper&period;js 事件流程控制

    /*! * 事件流程管理 * version: 1.0.0-2018.07.25 * Requires ES6 * Copyright (c) 2018 Tiac * http://www.cnblo ...

  10. 利用cookie存放模糊查询的信息

    将前台传入后台的查询条件,存放到cookie中,并加入响应对象中,将该查询条件存放入浏览器端.(会话cookie,存放在浏览器的内存中,浏览器关闭,cookie消失.[不设置路径,和生命周期]) 注意 ...