React Native 获取屏幕宽高:使用 Dimensions 组件
可以使用 Dimensions 组件来获取屏幕的宽、高,代码如下:
import { Dimensions } from 'react-native';
const screenWidth = Dimensions.get('window').width;
const screenHeight = Dimensions.get('window').height;
console.log('屏幕宽度:', screenWidth);
console.log('屏幕高度:', screenHeight);
以上代码将获取当前设备屏幕的宽度和高度,并输出到控制台。
原文地址: https://www.cveoy.top/t/topic/nirp 著作权归作者所有。请勿转载和采集!