Moiri Gamboni
Moiri Gamboni

Reputation: 21

Full-width Image in a ScrollView

I am trying to have an image inside a ScrollView taking the full width of the screen while keeping its aspect ratio (I don't want a fixed background image). The answers in https://github.com/facebook/react-native/issues/950 seem to work for a View but not a ScrollView.

The null width/height trick just makes the image disappear. Setting the width using Dimensions.get('window').width does not work for some reason; it leaves some space either on the top and bottom or the left and right of the image depending on its aspect ratio.

I can't use Image.getSize() as the image is local and would rather avoid hard-coding the dimensions as I have many other images that need to be styled this way. I have tried many other combinations of flex, alignSelf, etc. but none seem to work.

Upvotes: 2

Views: 2924

Answers (1)

samthui7
samthui7

Reputation: 943

Setting ScrollView's style={{width: "100%"}} works for me.

Upvotes: 2

Related Questions