屏幕适配之获取屏幕的分辨率
程序员文章站
2022-06-08 22:51:50
...
import React, {Fragment} from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
} from 'react-native';
import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
//引入
var Dimensions = require('Dimensions');
const App = () => {
return (
<Fragment>
<View style={styles.container}>
<Text>当前屏幕的宽度:{Dimensions.get('window').width}</Text>
<Text>当前屏幕的高度:{Dimensions.get('window').width}</Text>
<Text>当前屏幕的分辨率:{Dimensions.get('window').scale}</Text>
</View>
</Fragment>
);
};
const styles = StyleSheet.create({
container: {
//占满屏幕
flex:1,
//设置主轴的对齐方式
justifyContent:'center',
//设置侧轴的对齐方式
alignItems:'center'
}
});
export default App;