我开始学习本机反应,但遇到了问题。 我需要一张要在背景中重复的图像,但是它已经被拉伸了。 似乎resizeMode无法正常工作。
import React, { Component } from 'react';
import { Image, ImageBackground, StyleSheet, Button, View, Text } from 'react-native';
const styles = StyleSheet.create({
home: {
flex: 1,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'transparent',
},
backgroundImage: {
flex: 1,
resizeMode: 'repeat',
backgroundColor: '#882829'
}
});
export class HomeScreen extends Component {
render() {
return (
<View style={{flex: 1}}>
<ImageBackground source={require('../assets/stain_pattern.png')} style={styles.backgroundImage}>
<View style={styles.home}>
<Text>Home Screen</Text>
<Button
title="Go to Details"
onPress={() => this.props.navigation.navigate('Details')}
/>
</View>
</ImageBackground>
</View>
);
}
}
答案 0 :(得分:0)
您需要使用imageStyle = {{resizeMode:'repeat'}}。请参阅文档link
您需要以图片样式应用重复
<ImageBackground source={require('../assets/stain_pattern.png')} style={styles.backgroundImage} imageStyle={{resizeMode: 'repeat'}}>
<View style={styles.home}>
<Text>Home Screen</Text>
<Button
title="Go to Details"
onPress={() => this.props.navigation.navigate('Details')}
/>
</View>
</ImageBackground>