写出 React Native 中获取屏幕宽、高的代码
可以使用Dimensions组件来获取屏幕宽、高的值,具体代码如下:
import { Dimensions } from 'react-native';
const screenWidth = Dimensions.get('window').width;
const screenHeight = Dimensions.get('window').height;
以上代码中,Dimensions.get('window')返回的是包含屏幕宽、高信息的对象,我们通过.width和.height来获取屏幕的宽、高。
原文地址: https://www.cveoy.top/t/topic/bVeX 著作权归作者所有。请勿转载和采集!