React Native 中的屏幕宽度 [英] Screen width in React Native

查看:33
本文介绍了React Native 中的屏幕宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 React Native 中获取屏幕宽度?我需要它,因为我使用了一些重叠的绝对组件,并且它们在屏幕上的位置会随着不同的设备而变化.

How do I get screen width in React native? I need it because I use some absolute components that overlap and their position on screen changes with different devices.

推荐答案

在 React-Native 中,我们有一个名为 Dimensions 的选项

In React-Native we have an Option called Dimensions

在包含图像、文本和其他组件的顶部变量中包含维度.

Include Dimensions at the top var where you have include the Image,and Text and other components.

然后在你的样式表中你可以使用如下,

Then in your Stylesheets you can use as below,

ex: {
width: Dimensions.get('window').width,
height: Dimensions.get('window').height
}

这样就可以得到设备窗口和高度了.

In this way you can get the device window and height.

这篇关于React Native 中的屏幕宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆