React Native responsive image width while width/height ratio of image keeps the same

后端 未结 4 1493
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 14:35

I want a React Native Image to have a width of 50% of the available screen-width, no modification to width:height ratio of the image.

Any hints how to solve this?

4条回答
  •  走了就别回头了
    2021-02-14 15:38

    Use resize mode cover and set the width to ScreenWidth / 2 you can retrive the screen width using Dimensions component

    //Get screen width using Dimensions component 
    var {width} = Dimensions.get('window');
    //....
    //In image style 
    image:{
       width: width * 0.5
    }
    //In render function
    
    

    Edit adding overflow

    //add overflow : visible 
    
    

提交回复
热议问题