如何在本机反应中使用高度自动? [英] how to use Height auto in react native?

查看:31
本文介绍了如何在本机反应中使用高度自动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在浏览器中,可以指定图像的宽度,可以将高度设置为自动.这将使图像在绑定到指定宽度的同时保持纵横比.事先不知道高度和纵横比

In a browser, the width of an image can be specified and height can be set to auto. This will let the image retain aspect ratio while being bound to the specified width. Neither Height nor aspect ratio is known beforehand

如何在 React Native 中做同样的事情?Height 属性只能接受数值.

How can I do the same in react native? Height property can only accept number values.

推荐答案

解决方法:从 react-native 获取 Dimensions 模块.您可以使用 Dimensions.height/width 从此模块获取屏幕尺寸.然后,您可以使用以下内容设置图像样式:

Workaround: get Dimensions module from react-native. You can get screen size from this module using Dimensions.height/width. Then you can set you image style with something like this:

image: {
  height: Dimensions.height * 0.8,
  resizeMode: 'contain'
}

这篇关于如何在本机反应中使用高度自动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆