ReactNative屏幕适配、获取屏幕分辨率

获取当前屏幕的宽度、高度、分辨率

导入信息一般都用require 关键字
格式:var XXXX = require('XXXX');

//首先要导入Dimensions包
var Diemnsions = require('Dimensions');


export default class App5 extends Component<{}> {
  render() {
    return (
      

         当前屏幕的宽:{Diemnsions.get('window').width} 
         当前屏幕的高:{Diemnsions.get('window').height} 
         当前屏幕的分辨率:{Diemnsions.get('window').scale} 

      
    );
  }
}

const styles = StyleSheet.create({
  container:{
    marginTop:20,
    marginLeft:20,
    marginRight:20,
    marginBottom:20,
    flex:1,
    backgroundColor:'red',
    justifyContent:'center',
    alignItems:'center',
  },
});

你可能感兴趣的:(react-native)