在 React Native 中保持全宽图像的纵横比 [英] Maintain aspect ratio of image with full width in React Native

查看:81
本文介绍了在 React Native 中保持全宽图像的纵横比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于标签的查询.我想要一个图像占据父的整个宽度,我使用 alignSelf:stretch,但我也希望高度是根据图像的纵横比.我怎样才能实现这样的目标?

I have a query regarding tag. I want an image to take entire width of parent which I do using alignSelf:stretch, but I also want the height to be according to the aspect ratio of the image. How can I achieve something like this?

所以我想要一种方法来将高度指定为图像宽度的比率.

So I want a way to specify the height as a ratio of the width of the Image.

推荐答案

使用 style={{ aspectRatio: 3/2 }} 对于宽高比为 3:2 的水平图像.

Use style={{ aspectRatio: 3/2 }} for a horizontal image with width to height ratio of 3:2.

文档:https://facebook.github.io/react-native/docs/layout-props.html#aspectratio

(适用于 RN 0.40+)

(Available in RN 0.40+)

这篇关于在 React Native 中保持全宽图像的纵横比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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