React Native尺寸不一致的单位

huangapple go评论57阅读模式
英文:

React Native Dimensions Inconsistent Units

问题

我有一个视图宽度设置为80(使用Native Base):

  <Box
    maxW="80"
    w="80"
    rounded="lg"
    overflow="hidden"
    borderColor="coolGray.200"
    borderWidth="1"
  >

应该有足够的空间,可以在屏幕上容纳3个这些组件。当我使用 `const { width } = useWindowDimensions()` 时,我的iPad mini的宽度值返回为 `1133`。

当我检查组件时,它的宽度返回为 `328`。

在尺寸不一致的情况下,我该如何确定一行可以容纳多少个项目?例如,将80转换为328,或将1133减小到与视图的单位相同?

谢谢你的帮助!

[![点击图片描述][1]][1]


  [1]: https://i.stack.imgur.com/E5iXJ.jpg
英文:

I have a view width that has been set to 80 (using Native Base):

      <Box
        maxW="80"
        w="80"
        rounded="lg"
        overflow="hidden"
        borderColor="coolGray.200"
        borderWidth="1"
      >

There should be enough for 3 of these components to fit across a screen. When I use const { width } = useWindowDimensions(), the value for my iPad mini comes back as 1133 for the width.

When I do an inspection of the component, it comes back as being 328 in width.

How would I go about determining how many items can fit in a row when the dimensions don't seem to line up? E.g, Converting 80 to 328, or reducing 1133 to be in the same units as the view?

Thanks for your help!

React Native尺寸不一致的单位

答案1

得分: 0

NativeBase 单位原来是 4 dp 的值。因此,对于 w="80",它是 320dp。

https://github.com/GeekyAnts/NativeBase/discussions/5690

英文:

It turns out that NativeBase units are a value of 4 dp. So for w="80", it's 320dp.

https://github.com/GeekyAnts/NativeBase/discussions/5690

huangapple
  • 本文由 发表于 2023年2月6日 04:38:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355352.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定