简体   繁体   English

计算两个操作系统 [React Native] 的响应高度、宽度和字体大小的最佳方法是什么?

[英]what is the best way to Calculate responsive height, width and font-size for both operating system [React Native]?

what is the best practice to calculate height, width and font-size for both operating system?计算两个操作系统的高度、宽度和字体大小的最佳做法是什么?

There is an easy way you can deal with it.有一种简单的方法可以处理它。

1. 1.

import {Dimensions} from 'react-native';
let heightOfScreen = Dimensions.get('window').height
let width = Dimensions.get('window').width

And now suppose in your phone you have the height 100 to be correct, and your phone height is 640 pixels, so do, * (100/640) 100 = 15.6 so now you can set any view height to <View style={{height:15.6*heightOfScreen}} > and it willbe dynamic for all mobile devices, both cross platform, you dont have to worry about this looks small in some phone and all.现在假设在您的手机中,您的高度为 100 是正确的,并且您的手机高度为 640 像素,所以,* (100/640) 100 = 15.6所以现在您可以将任何视图高度设置为<View style={{height:15.6*heightOfScreen}} >并且对于所有移动设备都是动态的,无论是跨平台的,你不必担心这在某些手机中看起来很小。 Ive used this and its one of the best in built feature of react-native to provide screen dimensions.我已使用此功能及其 react-native 的最佳内置功能之一来提供屏幕尺寸。 Simliarly you can do for width too.同样,您也可以为宽度做。

Hope it helps.希望能帮助到你。 feel free for doubts随时怀疑

You can import Dimensions from react-native and you can calculate the height and width of the device screen.您可以从 react-native 导入尺寸,您可以计算设备屏幕的高度和宽度。 And by calculating height & width you can use them accordingly as per your need.通过计算高度和宽度,您可以根据需要相应地使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM