2017-10-18 96 views
1

我試圖添加一個圖像(由圖像全尺寸)到一個ScrollView組件,它的想法是讓圖像在它自己的大小(不限制它),但而是讓水平和垂直滾動(取決於圖像)。 所以我使用Image.getSize()爲它ScrollView內,這裏是我的組件,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

你可以在水平滾動視圖中水平移動垂直。爲了得到兩個你可以嵌套他們:

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