2016-10-03 110 views
0

我想在我的反應原生android和iOS應用程序中顯示靜態圖像。它在iOS應用中運行良好。但我無法在Android應用程序中顯示圖像。以下是我的代碼:無法在Android中顯示靜態圖像與反應原生

<Image source ={require('../images/background.png')} 
 
       style ={styles.imageStyle}> 
 
</Image> 
 

 
var styles = StyleSheet.create({ 
 
    container: { 
 
    flex: 1, 
 
    alignSelf: 'stretch' 
 
    }, 
 
    imageStyle: { 
 
    flex: 1, 
 
    margin:10, 
 
    width: undefined, 
 
    height: undefined, 
 
    backgroundColor:'transparent', 
 
    justifyContent: 'center', 
 
    alignItems: 'center' 
 

 
    }

我已經把圖像「background.png」下繪製 - ** dpi的文件夾,以及根據所提到的圖片文件夾。

它適用於我的iOS應用程序從圖像文件夾中挑選圖像,但不適用於android。 我正在使用react-native版本0.33

在此任何幫助將不勝感激!

編輯: 它不會在這裏也工作:

<View key={answer.ID}> 
 
    <OnTouchHighlightWidget key={answer.ID} onPress={() => {this.props.onSelect(answer)}}> 
 
      <Image source={this.getImageUrl(answer)} style={{flex:1,margin:10,width: 90, height: 95}} /> 
 
</OnTouchHighlightWidget> 
 
</View>

我已經把image_holo.png同一目錄下的js文件和相應的繪製 - ** DPI文件夾。它適用於iOS。但不是在Android上!

+0

這是一個完整的封面背景圖片? – EQuimper

+0

是的。這是一張背景圖片。 – Sachin

回答

0

您需要在您的imageStyle中定義widthheight

+0

感謝您的建議,但我已經這樣做了。沒有成功。 – Sachin

0

試試這是一個完整的背景圖像封面。

<Image source ={require('../images/background.png')} 
       style ={styles.imageStyle}> 
</Image> 

var styles = StyleSheet.create({ 
    container: { 
    flex: 1, 
    alignSelf: 'stretch' 
    }, 
    imageStyle: { 
    flex: 1, 
    margin:10, 
    width: null, 
    height: null, 
    backgroundColor:'transparent', 
    justifyContent: 'center', 
    alignItems: 'center' 

    } 
+0

沒有。它不起作用。我在我的問題中更新過的其他地方使用過圖片。但它也不起作用。它適用於iOS,但不適用於Android :( – Sachin

+0

而且你沒有添加任何寬度和高度?所以你什麼都看不到?如果是的話我會去看看我認爲有一次這個問題 – EQuimper

+0

你的圖像是否在視圖內? – EQuimper