首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-native expo中的LinearGradient高于ImageBackground

react-native expo中的LinearGradient高于ImageBackground
EN

Stack Overflow用户
提问于 2018-11-13 02:31:46
回答 3查看 5.8K关注 0票数 3

在我的react原生expo应用程序中,我有一个背景图像,它在所有屏幕上都采用了完全的高度和宽度,我想在背景图像上放置一个线性渐变,但它不起作用,图像总是出现在渐变之上,这是代码:

代码语言:javascript
复制
    import React, { Component } from 'react';
    import { LinearGradeint } from 'expo';
    import { Text, StyleSheet, ImageBackground } from 'react-native';

    class App extends Component {

      render() {

        return(
          <View style={styles.container}>
          <LinearGradient
          colors={['#4c669f', '#3b5998', '#192f6a']}>
            <ImageBackground source={require('./images/background.jpg')} style={styles.backgroundImage}>
            <View style={{width: "100%"}}>
            <Text>
              HI
            </Text>
          </View>
           </ImageBackground>
          </LinearGradient>
          </View>
        )
      }
    }

    const styles = StyleSheet.create({
      container: {
        flex: 1,
      },
      backgroundImage: {
        height: '100%',
        width: '100%',
        flex: 1,
      },
    export default App;
EN

回答 3

Stack Overflow用户

发布于 2018-12-24 16:45:17

尝试将LinearGradient组件放入ImageBackground中。

代码语言:javascript
复制
<ImageBackground source={require('./images/background.jpg')} style={styles.backgroundImage}>
     <LinearGradient colors={['#4c669f', '#3b5998', '#192f6a']} />
          <View style={{width: "100%"}}>
          </View>
</ImageBackground>
票数 3
EN

Stack Overflow用户

发布于 2019-12-21 02:03:10

在LinearGradient上添加绝对位置:

代码语言:javascript
复制
<LinearGradient
   colors={['#4c669f', '#3b5998', '#192f6a']}
   style={{
      position: 'absolute',
      left: 0,
      right: 0,
      top: 0,
      height: '100%'
   }}
/>
票数 1
EN

Stack Overflow用户

发布于 2021-08-31 10:39:09

这对我很有效:

代码语言:javascript
复制
<ImageBackground
  source={require('../../assets/img/background.png')}
  resizeMode="cover"
  style={{
    height: '100%',
    width: '100%',
    flex: 1,
  }}>
  <LinearGradient
    colors={[
      'rgba(255,180,113,0.75)',
      'rgba(255,107,11,0.75)',
      'rgba(255,180,113,0.75)',
    ]}
    style={{flex: 1, justifyContent: 'center'}}>

    {** CODE **}

  </LinearGradient>
</ImageBackground>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53268084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档