Dimensions
获取设备的宽高以及尺寸信息
index.android.js: import {AppRegistry} from 'react-native'; import App from './App'; AppRegistry.registerComponent('LeecoBrowser', () => App); App.js:
import React, { Component } from 'react'; import { View, Text, Dimensions, } from 'react-native'; class App extends Component { constructor(props) { super(props); } componentWillMount() { //let {width,height,scale,fontScale} = Dimensions.get("screen") let {width,height,scale,fontScale} = Dimensions.get("window") console.log("width",width) console.log("height",height) console.log("scale",scale) console.log("fontScale",fontScale) } render() { return (
'width', 411.42857142857144 'height', 731.4285714285714 'scale', 2.625 'fontScale', 2.625
横屏结果:
'width', 731.4285714285714 'height', 411.42857142857144 'scale', 2.625 'fontScale', 2.625