android - React Native 中默认的样式单位是什么?

标签 android css reactjs material-design react-native

我正在为一个开源元素做贡献,我正在为 React Native 开发 Material 设计。我在工作中受阻,无法对 UI 级别进行一些增强。填充、对齐等,

这是抽屉 Material 设计的官方规范-

According to the spec of Material Design

在上图中,测量的UNITdp

但是,在我的 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/

相关文章:

java - 如何告诉 ProGuard 保留私有(private)字段而不指定每个字段

css - 如何对齐 facebook 插件

javascript - Wordpress 自定义字段 - Javascript 中的 CSS

reactjs - React (Next.js) > 无效的 ARIA 属性 `ariaHidden` ,您的意思是 `aria-hidden` 吗?

javascript - 如何在react中将html属性设置为静态

javascript - Reactjs 在 for 循环结束之前不会渲染

android - 面部跟踪器 CameraSource Android : How to brighten front camera quality?

java - 如何避免将内容写入文件时的同步问题 - Java(android)

android - 使用 usageStats.getTotalTimeInForeground() 获取设备中每个应用程序在前台花费的时间

html - 将边框线添加到 Bootstrap 网格