React-Native ImageBackground 重复不起作用
React-Native ImageBackground repeat not working
开始学习react-native,遇到了一个问题。
我需要一个图像在背景中重复,但它被拉伸了。
似乎 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>
);
}
}
您需要使用 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>;
开始学习react-native,遇到了一个问题。 我需要一个图像在背景中重复,但它被拉伸了。 似乎 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>
);
}
}
您需要使用 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>;