2017-10-07 28 views
0

在反應天然的,我渲染圖像像下面的代碼:反應機映像包含空空間

<Image 
    source={{ 
     uri: downloadDest, 
     scale: 1 
    }} 
     style={styles.image} 
     resizeMode='contain' 
    > 
</Image> 

image: { 
    flex: 1, 
    backgroundColor: 'blue', 
}, 

此代碼呈現像以下的圖像,在這種情況下我需要calc下圖像和父視圖之間空填充。

如何計算W,H,圖像高度和圖像寬度?

enter image description here

enter image description here

回答

0
  • resizeMode是一個樣式道具。
  • 如果您想優先填充圖像質量的差距,請嘗試resizeMode:'stretch'或'cover'。

這應該工作:

<Image 
    source={{ 
     uri: downloadDest, 
     scale: 1 
    }} 
     style={styles.image} 
    > 
</Image> 

image: { 
    flex: 1, 
    resizeMode: 'cover', //or stretch/contain 
    backgroundColor: 'blue', 
}, 
+0

我需要渲染正確的縱橫比,但在使用時拉伸或封面圖像縱橫比變錯 –

+0

蓋不改變縱橫比的圖像,但部分地區的圖像不會出現在你的「視圖」 –