有一幅固定的图片aspectRatio
。何时调整尺寸以适合容器或计算高度width: '100%'
?
要将图片仅以width = 100%放入容器中,请尝试width = 100%+ resizeMode = contain
例如
<Image
resizeMode={'contain'}
style={{ flex:1,
width:'100%',
aspectRatio: 1 }}
source={{uri: "https://www.yoursite.com/images/" + item.photo}}
/>
要么
import { Image, StyleSheet, View } from 'react-native';
const image = () => (
<View style={styles.imgContainer}>
<Image style={styles.image} source={require('assets/images/image.png')} />
</View>
);
const style = StyleSheet.create({
imgContainer: {
flexDirection: 'row'
},
image: {
resizeMode: 'contain',
flex: 1,
aspectRatio: 1 // Your aspect ratio
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句