javascript - 如何在 native react 中设置背景图像?

标签 javascript react-native background-image jsx

我正在尝试在 React Native 中设置背景图片。我想要一张背景封面图片。我已经像下面那样做了

<ScrollView>
    <View>
        <Image source={ require('../Images/5.jpg') } style = { styles.image } />
            {
                this.state.details.map(a =>
                    <View>
                        <Text style={ styles.textStyle } > { a.content = a.content.replace(regex, '') } < /Text>
                        < RadioForm style= {{ width: 350 - 30 }} outerColor = "#080103" innerColor = "#FF5733" itemShowKey = "label" itemRealKey = "item" dataSource = { transform(a.options) } onPress = {(item)=>this._onSelect(item)}/>
                    </View>)
            }
    </View>
</ScrollView>

const styles = StyleSheet.create({
    image: {
        flex: 1,
        resizeMode: 'cover',
        position: 'absolute',
        width: "100%",
        flexDirection: 'column'
    },
    textStyle: {
        fontSize: 16,
        color: '#000',
        padding: 5,
    },
});

但是我得到了这样的东西

this is i'm getting

最佳答案

您可能需要在 ScrollView 之外添加 ImageBackground 并确保将 flex 传递给 ImageBackground 样式'

例如

<View style={{flex: 1}}>
        <ImageBackground
          resizeMode={'stretch'} // or cover
          style={{flex: 1}} // must be passed from the parent, the number may vary depending upon your screen size
          source={require('/*Your Image Path*/')}
        >
          <ScrollView>
            {/*Render the children here*/}
          </ScrollView>
        </ImageBackground>
      </View>

关于javascript - 如何在 native react 中设置背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49273616/

相关文章:

html - 允许背景溢出?

javascript - 从 Observable 列表创建 Observable 对象

javascript - 如何为输入字段提供触发器

javascript - 如何使用 nervgh 的 Angular-File-Upload 发送 formData

javascript - 如何确保在 Firebase 查询填充数组后调用 setState?

react-native - 自定义发送按钮和清除 textInput react-native-gifted-chat

css - 用作背景图像时如何缩放 CSS Sprite ?

javascript - Rocket.Chat自定义JavaScript拦截新消息

javascript - ImageBackground 包装器内的 React Native Text 未显示(带图像)

html - Windows 中的 Chrome 缩小 (cntrl - ) 隐藏线性渐变条纹颜色