You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native <Image/>本地图片宽设100%时比例异常问题

React Native 本地Image组件宽高比例异常问题

问题现象

  • 给<Image/>组件设置width: "100%"和正确的aspectRatio属性时,本地图片在Android和Web端会显示错误的宽高比例
  • 在线图片无此问题,仅需给本地图片的样式添加height: "auto",就能恢复正常比例显示

代码示例

const styles = StyleSheet.create({
  img: { width: "100%" }
})

// 显示异常:本地图片比例错误
<Image
  source={require("./local-img.webp")}
  style={{ ...styles.img, aspectRatio: 646 / 1064 }}
/>

// 显示正常:添加height: "auto"后恢复正确比例
<Image
  source={require("./local-img.webp")}
  style={{ ...styles.img, height: "auto", aspectRatio: 646 / 1064 }}
/>

// 显示正常:在线图片无需额外设置height
<Image
  source={{ uri: "https://online-img.webp" }}
  style={{ ...styles.img, aspectRatio: 646 / 1064 }}
/>

效果对比

预期效果

预期效果

实际效果(未添加height: "auto"时)

实际效果

内容的提问来源于stack exchange,提问作者object417

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 23:55:20