我正在尝试将图像(按图像全尺寸)添加到ScrollView
组件中,其目的是让图像在其自身大小上(不限制它),而是让滚动水平和垂直(取决于图像)。
所以我在Image.getSize()
中使用ScrollView
,这是我的组件,
import React, { Component } from 'react';
import { Image, ScrollView } from 'react-native';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
width: 10,
height: 10,
image: 'http://www.francedimanche.fr/parole/wp-content/uploads/2017/08/Angelina-Jolie.png',
}
}
componentDidMount() {
Image.getSize(this.state.image, (width, height) => {
this.setState({ width, height });
});
}
render() {
return (
<ScrollView>
<Image
style={{ width: this.state.width, height: this.state.height }}
source={{uri: this.state.image}}
/>
</ScrollView>
);
}
}
谢谢!
答案 0 :(得分:1)
您可以在ScrollView中纵向移动或。为了得到这两者,你可以嵌套它们:
<ScrollView horizontal={true}>
<ScrollView>
<Image
style={{ width: this.state.width, height: this.state.height }}
source={{uri: this.state.image}}
/>
</ScrollView>
</ScrollView>