我正在为一个开源元素做贡献,我正在为 React Native 开发 Material 设计。我在工作中受阻,无法对 UI 级别进行一些增强。填充、对齐等,
这是抽屉 Material 设计的官方规范-
在上图中,测量的UNIT为dp。
但是,在我的 React Native 代码中,我发现没有提到这样的单元。考虑到它是“react native”,我很困惑它是 px 还是 dp。
我什至查看了 React Native for Style 的官方文档零件。我在任何地方都没有看到提及。
我的代码看起来像-
const styles = {
touchable: {
paddingHorizontal: 16,
marginVertical: 8,
height: 48
},
item: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
},
icon: {
position: 'relative',
},
value: {
flex: 1,
paddingLeft: 34,
top: 2
},
label: {
top: 2
}
},
请你告诉我,这是像素还是 dp?还有,是 1px = 1dp
?
最佳答案
来自 docs :
All dimensions in React Native are unitless, and represent density-independent pixels. Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.
所以是的,React Native 中的单元在 dp
中。如果要将它们转换为像素,请使用 PixelRatio.getPixelSizeForLayoutSize()
关于android - React Native 中默认的样式单位是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34493372/