【问题标题】:Gradient background is not applied for screen渐变背景不适用于屏幕
【发布时间】:2019-12-24 12:11:37
【问题描述】:

我有以下渲染功能:

    <View style={styles.container}>
            <LinearGradient colors={['#4c669f', '#3b5998', '#192f6a']} start={[0, 0]} end={[1, 1]} />
            <View ... >
    </View>

我创建了它,因为我想为我的屏幕创建一个渐变背景。但是当我打开这个屏幕时,我看到这个背景没有被应用。那么,我的代码出了什么问题?

【问题讨论】:

  • 例如start={{x: 0, y: 0}} end={{x: 1, y: 0}}这是您需要指定开始和结束的方式

标签: react-native linear-gradients


【解决方案1】:

根据文档react native linear gradient,您需要将 start 和 end 指定为指定 x 和 y 坐标的对象。

          <View style={styles.container}>
            <LinearGradient 
              colors={['#4c669f', '#3b5998', '#192f6a']} 
              start={{x: 0, y: 0}} 
              end={{x:1, y: 1}} 
            />
          <View>

【讨论】:

    【解决方案2】:

    您的代码一切正常。

    您只需将样式也添加到您的子组件 style = {{flex:1}} 这将呈现渐变。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-10
      • 2021-04-28
      • 2016-06-12
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      相关资源
      最近更新 更多