寬高比陣營天然:0.47.1渲染網絡圖像和保持高度
如何將保持高度的縱橫比時的寬度爲100%?基本上我想在保持縱橫比的同時自動縮放高度。圖像將顯示在FlatList
(不一定,如果有其他事情我很樂意更改FlatList
)。圖像被從data
數組,它在state
設置顯示:
export default class ImageTest extends Component {
constructor(props) {
super(props)
this.state = {
data : [
{id: 1, name: "image1", url: "http://urlOfImage.com/1.jpg"}
{id: 2, name: "image2", url: "http://urlOfImage.com/2.jpg"}
{id: 3, name: "image3", url: "http://urlOfImage.com/3.jpg"}
{id: 4, name: "image4", url: "http://urlOfImage.com/4.jpg"}
{id: 5, name: "image5", url: "http://urlOfImage.com/5.jpg"}
];
}
}
render() {
return (
<View style={styles.container}>
<FlatList
data={this.state.data}
renderItem = {({item})=>
<Text style={styles.item}>{item.name}</Text>
<Image
source={uri: item.url}
style={styles.myImageStyle} />
}
/>
</View>
)
}
}
const styles = StyleSheet.create(
myImageStyle: {
width: Dimensions.get('window').width,
height: /* WHAT DO I PUT HERE ?? */
}
)
因此圖像可以在高度發生變化,原來的高度可以是700像素,一些也許1200像素,或者甚至方形的圖像。我如何定義每個圖像的高度,因爲它們來自數組?
非常感謝
看看[react-native-scalable-image](https://www.npmjs.com/package/react-native-scalable-image) –