ScrollView中的大图像不会滚动

时间:2017-10-18 14:58:09

标签: react-native react-native-scrollview

我正在尝试将图像(按图像全尺寸)添加到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>
    );
  }
}

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以在ScrollView中纵向移动。为了得到这两者,你可以嵌套它们:

  <ScrollView horizontal={true}>
    <ScrollView>
      <Image
        style={{ width: this.state.width, height: this.state.height }}
        source={{uri: this.state.image}}
      />
    </ScrollView>
  </ScrollView>