美文网首页
reactnative Flexbox布局

reactnative Flexbox布局

作者: linzaifei | 来源:发表于2017-06-08 10:07 被阅读10次

使用flexDirection、alignItems和 justifyContent

三个样式属性就已经能满足大多数布局需求。译注:这里有一份简易布局图解,可以给你一个大概的印象。

flexDirection 可以决定布局的主轴 子元素是应该沿着水平轴(row)方向排列,还是沿着竖直轴(column)方向排列呢?默认值是竖直轴(column)方向。

当flexDirection = row, column

export default class RNFlex extends Component{
  render() {
  return (
      <View style = {styles.container}>
          <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} />
          <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />
          <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />
      </View>
     );
     }
}
  const styles = StyleSheet.create({
      container: {
      height :300,
      margin:40,
     flexDirection :'column'
    },
});
flexDirection = row flexDirection = column

justifyContent可以决定其子元素沿着主轴的排列方式。子元素是应该靠近主轴的起始端还是末尾段分布呢?亦或应该均匀分布?对应的这些可选项有:flex-start、center、flex-end、space-around以及space-between。

<View style = {{height : 400,margin :30,justifyContent:'flex-start',flexDirection:'row',backgroundColor:'red'}}>
        <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} />
        <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />
        <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />
</View> 
flexDirection = row ,justifyContent = flex-start flexDirection = column ,justifyContent = flex-start flexDirection = column ,justifyContent = center flexDirection = row ,justifyContent = center flexDirection = column ,justifyContent = flex-end flexDirection = row ,justifyContent = flex-end flexDirection = row ,justifyContent = space-around flexDirection = column ,justifyContent = flex-around flexDirection = row ,justifyContent = space-between

]

flexDirection = column ,justifyContent = space-between

alignItems可以决定其子元素沿着次轴(与主轴垂直的轴,比如若主轴方向为row,则次轴方向为column)的排列方式。子元素是应该靠近次轴的起始端还是末尾段分布呢?亦或应该均匀分布?对应的这些可选项有:flex-start、center、flex-end以及stretch。

注意:要使stretch选项生效的话,子元素在次轴方向上不能有固定的尺寸。以下面的代码为例:只有将子元素样式中的width: 50去掉之后,alignItems: 'stretch'才能生效。

关于Flexbox 布局的流程 示意图

相关文章

  • ReactNative flexbox布局

    采用Flex布局的元素,称为Flex容器(flex container),简称容器,它的所有子元素则是Flex容器...

  • reactnative Flexbox布局

    使用flexDirection、alignItems和 justifyContent 三个样式属性就已经能满足大多...

  • ReactNative Flexbox 布局

    what's the meaning of Flexbox? 答:The Flexible Moudle (弹性...

  • ReactNative→FlexBox布局

    Flexbox在布局中能够解决什么问题? 浮动布局 各种机型屏幕的适配 水平和垂直居中 自动分配宽度 一、简单的运...

  • ReactNative Flexbox布局

    1、flexDirection 决定布局的主轴(水平轴x) 默认值是竖直轴(column) 决定子元素是应该沿着水...

  • ReactNative布局FlexBox

    父容器布局属性 1.FlexDirection:主轴方向(String) row(横向正向布局) row-reve...

  • ReactNative之样式

    本节介绍: 样式高度与宽度使用Flexbox布局 样式 在ReactNative中仍然使用JavaScript来写...

  • ReactNative FlexBox布局简述

    关于FlexBox布局,我的理解上,先确定以谁为主,谁未次,然后根据主次方向开始布局。 ReactNative中文...

  • ReactNative学习——Flexbox布局

    关于FlexBox的资料可以参阅这篇博文:http://www.ruanyifeng.com/blog/2015/...

  • ReactNative开发-FlexBox布局

    前言 看过很多关于FlexBox布局的文章,但绝大部份都讲的多而乱,我初学的时候也是看的一脸懵逼。所以打算自己总结...

网友评论

      本文标题:reactnative Flexbox布局

      本文链接:https://www.haomeiwen.com/subject/iypwxxtx.html