ReactNative自学学院React NativeReact Native

react-native 布局篇之position

2016-06-27  本文已影响12387人  甘言川

position布局

position:enum('absolute','relative')。先简单的看一下示例图

Snip20160627_1.png
/**
 * Created by GXZ on 16/6/27.
 */
import React,{Component} from 'react';
import {
    Text,
    View,
    ScrollView
} from 'react-native';

export default class PositionExample extends Component {
    constructor(props) {
        super(props);
        this.state = {};
    }

    render() {
        return (
            <ScrollView>
                <View style={{flex:1}}>
                    <Text>FlexBox布局</Text>
                    <View style={styles.container}>
                        <View style={styles.box1}/>
                        <View style={[styles.box2]}/>
                        <View style={[styles.box3]}/>
                    </View>
                    <Text>position=relative,top:20</Text>
                    <View style={styles.container}>
                        <View style={styles.box1}/>
                        <View style={[styles.box2,{position:'relative',top:20}]}></View>
                        <View style={styles.box3}/>
                    </View>
                    <Text>position=absolute,top:20</Text>
                    <View style={styles.container}>
                        <View style={styles.box1}/>
                        <View style={[styles.box2,{position:'absolute',top:20}]}></View>
                        <View style={styles.box3}/>
                    </View>
                </View>
            </ScrollView>
        );
    }
}

const styles = {
    container: {
        height: 180,
        backgroundColor: '#CCCCCC',
        marginBottom: 10,
    },
    box1: {
        width: 50,
        height: 50,
        backgroundColor: '#FF0000'
    },
    box2: {
        width: 50,
        height: 50,
        backgroundColor: '#00FF00'
    },
    box3: {
        width: 50,
        height: 50,
        backgroundColor: '#0000FF'
    }
};
上一篇 下一篇

猜你喜欢

热点阅读