React-native 博览会中 ImageBackground 上方的 LinearGradient

Nat*_*ill 6 javascript linear-gradients react-native expo imagebackground

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

    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;
Run Code Online (Sandbox Code Playgroud)

小智 6

尝试将 LinearGradient 组件放入 ImageBackground 中。

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