1

我正在尝试将图像(按图像全尺寸)添加到ScrollView组件中,其想法是让图像具有自己的大小(不限制它),而是让水平和垂直滚动(取决于图像) . 所以我在Image.getSize()a 中使用它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>
    );
  }
}

谢谢!

4

1 回答 1

1

您可以在 ScrollView 中水平垂直。要获得两者,您可以嵌套它们:

  <ScrollView horizontal={true}>
    <ScrollView>
      <Image
        style={{ width: this.state.width, height: this.state.height }}
        source={{uri: this.state.image}}
      />
    </ScrollView>
  </ScrollView>
于 2017-10-18T15:28:00.543 回答