react native获取屏幕的宽度和高度

var Dimensions = require('Dimensions');
var {width,height} = Dimensions.get("window");//第一种写法
var width1 = Dimensions.get('window').width//第二种写法


export default class Demo extends Component {

    render() {
        return (
            <View style={styles.container}>
                <Text style={{marginTop:30}}>宽:{width} 高:{height}</Text>
            </View>
        );
    }

}
const styles = StyleSheet.create({
    container: {
        backgroundColor: '#F5FCFF',
    },
});

AppRegistry.registerComponent('Demo', () =>Demo);

 

posted @ 2018-10-15 14:01  新年新气象  阅读(3659)  评论(0编辑  收藏  举报