React native 反应本机图像背景重复不工作
我开始学习react母语,遇到了一个问题。 我需要一个图像在背景中重复,但它被拉伸了。 resizeMode似乎不起作用React native 反应本机图像背景重复不工作,react-native,repeat,imagebackground,React Native,Repeat,Imagebackground,我开始学习react母语,遇到了一个问题。 我需要一个图像在背景中重复,但它被拉伸了。 resizeMode似乎不起作用 import React, { Component } from 'react'; import { Image, ImageBackground, StyleSheet, Button, View, Text } from 'react-native'; const styles = StyleSheet.create({ home: { flex: 1,
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>
);
}
}
import React,{Component}来自'React';
从“react native”导入{Image、ImageBackground、样式表、按钮、视图、文本};
const styles=StyleSheet.create({
主页:{
弹性:1,
flexDirection:'列',
对齐项目:“居中”,
为内容辩护:“中心”,
背景色:“透明”,
},
背景图片:{
弹性:1,
resizeMode:'重复',
背景颜色:“#882829”
}
});
导出类主屏幕扩展组件{
render(){
返回(
主屏幕
this.props.navigation.navigate('Details')}
/>
);
}
}
您需要使用imageStyle={{resizeMode:'repeat'}}。参考文件
您需要在图像样式中应用“重复”
<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>;
主屏幕
this.props.navigation.navigate('Details')}
/>
;