【问题标题】:React native dimensions for Google Pixel XL and 2 XL为 Google Pixel XL 和 2 XL 反应原生尺寸
【发布时间】:2018-01-30 01:24:28
【问题描述】:

我在 Google Pixel XL 和 2 XL 中渲染乐透动画时遇到问题。但是我手头没有那个设备,有人知道反应原生单元的宽度和高度吗?或者您如何检测这些设备?

【问题讨论】:

  • 欢迎来到 Stack Overflow!为了给您一个很好的答案,如果您还没有看过How to Ask,它可能会对我们有所帮助。如果您可以提供minimal reproducible example,它可能也很有用。
  • 您可以使用 React Native 中的 Dimensions 来获取宽度和高度。

标签: react-native height width dimensions google-pixel


【解决方案1】:

您可以通过从 react-native 包本身导入 Dimensions 来实现,如下所示

import { Dimensions } from 'react-native';

const window = Dimensions.get('window');
const screenHeight = window.height;
const screenWidth = window.width;

并在任何元素中适当地使用它

<View style={{height: screenHeight - 80}}>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-05
    • 2018-10-19
    • 1970-01-01
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    相关资源
    最近更新 更多