【问题标题】:Big image inside ScrollView won't let scrollScrollView 中的大图像不会让滚动
【发布时间】:2017-10-18 14:58:08
【问题描述】:

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

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>
    );
  }
}

谢谢!

【问题讨论】:

    标签: react-native react-native-scrollview


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2017-12-04
      • 2021-07-20
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多