Css 如何保持给定宽度图像的纵横比?
我正在一个图像画廊上工作。我需要在Css 如何保持给定宽度图像的纵横比?,css,image,react-native,height,Css,Image,React Native,Height,我正在一个图像画廊上工作。我需要在列表视图中每行显示3个图像 renderCategory(category) { return ( <Image source={{uri: category.image}} style={styles.image}> <Text style={styles.headline}>{category.name}</Text> </Image>
列表视图中每行显示3个图像
renderCategory(category) {
return (
<Image source={{uri: category.image}} style={styles.image}>
<Text style={styles.headline}>{category.name}</Text>
</Image>
);
}
render() {
return (
<View>
<Button title="Back" color="#5c6bc0" onPress={this.onPress}/>
<ListView dataSource={this.state.dataSource} renderRow={this.renderCategory} contentContainerStyle={styles.list_view}/>
</View>
);
}
在这里,我努力记录图像的高度。是否可以使用react native中的给定宽度调整图像高度。示例代码:
image: {
width: Dimensions.get('window').width / 3 - 10 ,
height: Dimensions.get('window').width / 3 - 10,
margin:5,
resizeMode: 'contain',
}
示例代码:
image: {
width: Dimensions.get('window').width / 3 - 10 ,
height: Dimensions.get('window').width / 3 - 10,
margin:5,
resizeMode: 'contain',
}
例如,如果原始图像的宽度/高度为500像素x 1000像素。
你想保持收音机的静态宽度
const radio = 1000/500;
const static_width = Dimensions.get('window').width / 3;
image: {
height: static_width * radio,
width: static_width;
}
希望有帮助。例如,如果原始图像的宽度/高度为500像素x 1000像素。
你想保持收音机的静态宽度
const radio = 1000/500;
const static_width = Dimensions.get('window').width / 3;
image: {
height: static_width * radio,
width: static_width;
}
希望这有帮助。你能解释一下0.7的比例因子吗?0.7表示屏幕大小的70%。但我需要相对高度画廊中的图像应该具有相同的高度和宽度,对吗?这很有效。图像:{width:Dimensions.get('window')。width/3-10,height:Dimensions.get('window')。width/3-10,margin:5,resizeMode:'contain',}你能解释一下0.7的比例因子吗?0.7表示屏幕大小的70%。但是我需要相对高度画廊中的图像应该具有相同的高度和宽度,对吧?这很有效。图像:{width:Dimensions.get('window')。width/3-10,height:Dimensions.get('window')。width/3-10,margin:5,resizeMode:'contain',}你的意思是你需要保持图像的宽高比和你给出的宽度?你的意思是你需要保持图像的宽高比和你给出的宽度?如果图像源来自互联网,使用source={{uri:'http://example.com/some.png“}}
?我们不知道该资源的比例,是吗?@Halt在这种情况下,您可以使用Thank@IhorBurlachenkoWhat,如果图像源来自internet,则使用source={{uri:'http://example.com/some.png“}}
?我们不知道该资源的比例,是吗?@Halt在这种情况下,您可以使用thanke@IhorBurlachenko