zoukankan      html  css  js  c++  java
  • FlexBox布局的重要属性

    /**
     * Sample React Native App
     * https://github.com/facebook/react-native
     * @flow
     */
    
    import React, { Component } from 'react';
    import {
      AppRegistry,
      StyleSheet,
      Text,
      View
    } from 'react-native';
    
    /*--------------------第一个示例程序------------------*/
    
    class FlexBoxDemo extends Component {
      render() {
        return (
          <View style={styles.container}>
             <Text style = {{backgroundColor: 'red',height: 30}}>第一个</Text>
             <Text style = {{backgroundColor: 'green',height: 30}}>第二个</Text>
             <Text style = {{backgroundColor: 'yellow',height: 30}}>第三个</Text>
             <Text style = {{backgroundColor: 'blue',height: 30}}>第四个</Text>
        </View>
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
    
        // 注意: 父视图的高度是随子视图而决定的
    
        // 改变主轴的方向
        flexDirection: 'row',
        backgroundColor: 'purple',
        // 距离顶部间距
        marginTop:25,
        // 设置主轴的对齐方式
        justifyContent:'center',
        // 设置侧轴的对齐方式
        alignItems: 'flex-end'
      },
    });
    
    /*--------------------第二个示例程序------------------*/
    
    class FlexBoxDemo1 extends Component {
      render() {
        return (
            <View style={styles1.container}>
      <Text style = {{backgroundColor: 'red', 100}}>第一个</Text>
        <Text style = {{backgroundColor: 'green', 200}}>第二个</Text>
        <Text style = {{backgroundColor: 'yellow', 100}}>第三个</Text>
        <Text style = {{backgroundColor: 'blue', 120}}>第四个</Text>
        </View>
      );
      }
    }
    
    const styles1 = StyleSheet.create({
    
      container: {
    
        // 注意: 父视图的高度是随子视图而决定的
    
        // 改变主轴的方向
        flexDirection: 'row',
        backgroundColor: 'purple',
        // 距离顶部间距
        marginTop:25,
        // 设置主轴的对齐方式
        justifyContent:'center',
        // 设置侧轴的对齐方式
        alignItems: 'flex-end',
        // 设置图像换行显示,默认是不换行
        flexWrap: 'wrap',
        // 决定盒子的宽度  宽度 = 弹性宽度 * (flexGrow / 父View宽度)
        flex: 1,
    
      },
    })
    
    /*--------------------第三个示例程序------------------*/
    
    class FlexBoxDemo2 extends Component {
      render() {
        return (
            <View style={styles2.container}>
    
        <Text style = {{backgroundColor: 'red',height: 100,alignSelf: 'flex-start'}}>第一个</Text>
        <Text style = {{backgroundColor: 'green',height: 110}}>第二个</Text>
        <Text style = {{backgroundColor: 'yellow',height: 120}}>第三个</Text>
        <Text style = {{backgroundColor: 'blue',height: 130}}>第四个</Text>
        </View>
      );
      }
    }
    
    const styles2 = StyleSheet.create({
    
      container: {
    
        // 注意: 父视图的高度是随子视图而决定的
    
        // 改变主轴的方向
        flexDirection: 'row',
        backgroundColor: 'purple',
        // 距离顶部间距
        marginTop:25,
        // 设置主轴的对齐方式
        justifyContent:'center',
        // 设置侧轴的对齐方式
        alignItems: 'flex-start',
        // 设置图像换行显示,默认是不换行
        flexWrap: 'wrap',
        // 决定盒子的宽度  宽度 = 弹性宽度 * (flexGrow / 父View宽度)
        flex: 1,
      },
    })
    
    
    AppRegistry.registerComponent('FlexBoxDemo', () => FlexBoxDemo2);

  • 相关阅读:
    DBA_VMware虚拟机安装和简介(案例)
    DBA_Oracle基本体系内存和进程结构(概念)
    IREP_SOA Integration SOAP概述(概念)
    IREP_SOA Integration WSDL概述(概念)
    IREP_SOA Integration程序注释语法Annotations(概念)
    DBA_Oracle日志文件
    BPEL_Oracle BPEL新一代工作流介绍(概念)
    DBA_Oracle基本体系架构(概念)
    DBA_Tablespace表空间的概念和管控(概念)
    WebADI_Oracle ERP R12使用前WebADI设定(案例)
  • 原文地址:https://www.cnblogs.com/pengsi/p/5876160.html
Copyright © 2011-2022 走看看