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

后端 未结 4 1505
伪装坚强ぢ
伪装坚强ぢ 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:41

    Local images can be rendered without giving a fixed width and height but, for remote images you must provide dimensions as react-native cant calculate them on runtime. So, the following works for me

    
          
    
    

    and apply following styles.

    thumbContainer: {
        width: '100%',
        height: 400,
      },
      thumbnail: {
        flex: 1,
        width: undefined,
        height: undefined,
        resizeMode: 'cover'
      },
    

提交回复
热议问题