0

I am trying to display static images in my react-native android and iOS apps. It's working fine with iOS app. But I am not able to display image in android app. Following is my code:

<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'

  }

I have put the image 'background.png' under drawable-**dpi folders as well as under the mentioned images folder.

It works well in my iOS app picking image from images folder but not on android. I am using react-native version 0.33

Any help in this will be greatly appreciated!

Edit: It doesn't work here also:

<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>

I have put the image_holo.png under same directory as js file and respective drawable-**dpi folders. It works on iOS. But not on android!

Sachin
  • 217
  • 1
  • 4
  • 12

3 Answers3

0

You need to define the width and height in your imageStyle.

Georgios
  • 4,764
  • 35
  • 48
0

Try this for a full background image cover.

<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'

  }
EQuimper
  • 5,811
  • 8
  • 29
  • 42
0

Try creating a drawable folder in your android Studio under the res folder and copy your image to this folder,refer the link below to set it up (Android Studio: Drawable Folder: How to put Images for Multiple dpi?). Clean and rebuild your project on android studio,it works.

Thanmai C
  • 741
  • 1
  • 7
  • 10