React Native 中使用了哪些维度单位? [英] what dimension units are used in React Native?

查看:47
本文介绍了React Native 中使用了哪些维度单位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 React Native 定义一些样式维度时没有任何单位:

When using React Native to define some styling dimensions do not have any units:

welcome: {
  fontSize: 20,
  margin: 10,
}

我认为原因是因为它是跨平台代码,而 iOS 和 Android 使用不同的单位.

I assume the reason is because it's cross platform code, and iOS and Android use different units.

文档 不是非常有用,因为所有示例都使用 rem 单位,并且在任何地方都没有提及单位.

The docs are not very helpful since all the examples use rem units and there's no mention about units anywhere.

那么每个平台使用什么单位?

So what units are being used for each platform?

其他答案没有'不要说 Android 中使用了哪些单位.我假设它是 dp 但它没有在任何地方指定.

the other answer doesn't say what units are being used in Android. I'm presuming it's dp but it isn't specified anywhere.

推荐答案

单位是 iOS 的逻辑像素.请参阅 SO 问题 此处,该问题由React Native 的贡献者.

The units are logical pixels for iOS. See SO question here, which was answered by a contributor to React Native.

对于 Android,单位在 DIP 中,这有点类似于逻辑iOS 中的点(有一个很好的 write up 主题).如果你查看源代码 此处,您将看到它们将提供的值转换为 toPixelFromDIP.

For Android, the units are in DIP which is kinda similar to logical points in iOS (There is a nice write up on the subject). If you look at the source code here, you'll see that they convert the supplied value toPixelFromDIP.

这篇关于React Native 中使用了哪些维度单位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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