React native 反应本机方面适合图像
React native 反应本机方面适合图像,react-native,React Native,如何使图像宽度为父图像的25%,高度为保持原始宽高比所需的任何值?您可以如下编辑图像样式: <Image style={{ alignSelf: 'center', flex: 1, width: '25%', height: null, resizeMode: 'cover', borderWidth: 1, borderRadius: 75,
如何使图像宽度为父图像的25%,高度为保持原始宽高比所需的任何值?您可以如下编辑图像样式:
<Image
style={{
alignSelf: 'center',
flex: 1,
width: '25%',
height: null,
resizeMode: 'cover',
borderWidth: 1,
borderRadius: 75,
}}
source={{uri:'https://facebook.github.io/react/img/logo_og.png'}}
resizeMode="stretch"
/>
const style=StyleSheet.create({
图片:{
身高:80,
宽度:80,
resizeMode:“包含”
}
});
contain
是您需要的。但是还有更多的选项,如iOS中的Aspect Fill和Android中的Center Crop
图片:{
弹性:1,
宽度:空,
高度:空,
resizeMode:“包含”
}
也许你可以试试这个解决方案看看Dup:这并不能保持meWow的纵横比,我根本没想到这会起作用,但当我使用
height:null
以及设置width
和aspectRatio
值时,它工作得非常好!
<Image style={style.image} source={require('.....')} />
const style = StyleSheet.create({
image: {
height: 80,
width: 80,
resizeMode: 'contain'
}
});