简体   繁体   中英

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.

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. Ive used this and its one of the best in built feature of react-native to provide screen dimensions. 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. And by calculating height & width you can use them accordingly as per your need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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