【问题标题】:How can I rewrite this CSS for react native我如何重写这个 CSS 以响应原生
【发布时间】:2018-04-07 23:25:13
【问题描述】:

为 react native 编写此 CSS 属性时出现错误。

border-radius: 50% / 100%;

我尝试做:

borderRadius: '50% / 100%'

我收到一个错误,Java.lang.string 无法转换为 java.lang.double

【问题讨论】:

    标签: android css reactjs react-native


    【解决方案1】:

    拆分border-radius的简写属性,避免使用/

    border-radius: 50% / 100%;
    

    变成这样:

    border-top-left-radius: 50% 100%;
    border-top-right-radius: 50% 100%;
    border-bottom-right-radius: 50% 100%;
    border-bottom-left-radius: 50% 100%;
    

    【讨论】:

    • 仍然有这个问题,我做到了:borderBottomLeftRadius: '50% 100%', borderBottomRightRadius: '50% 100%', borderTopLeftRadius: '50% 100%', borderTopRightRadius: '50% 100%'
    【解决方案2】:

    在 react-native 中我们不能在边界半径上设置百分比,你必须使用数字。

    可以设置一个高的borderRadius,然后使用onLayout获取视图的实际宽度,然后设置边框半径。或者只是设置一个高边界半径。

    最好是你知道尺寸,然后用它除以 2。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-24
      • 2020-03-03
      • 2016-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多