【问题标题】:What should be the sizes of the Images for supporting both iOS & Android in React-Native在 React-Native 中支持 iOS 和 Android 的图像的大小应该是多少
【发布时间】:2019-08-05 08:53:48
【问题描述】:

我是一名 iOS 开发者,最近开始用 React-native 开发一个 APP。 在 iOS 中,我们提供 3 种类型的图像 x、@2x 和 @3x 来支持所有设备。根据一些开发者网站/博客,在使用 android 时,我看到他们使用许多分辨率图像大小,如 ldpi、mdpi、hdpi、xhdpi 等。

我的问题是

所以,在 react-native 中,我应该使用什么尺寸的图像,以便它适合 iOS 和 Android 设备。

在我的登录屏幕中,我使用的图像尺寸是“640 X 1138”和“750X1334”,但在 Android 设备中,图像在屏幕的顶部和底部被修剪,在 iOS 设备中,这很好.

【问题讨论】:

  • 为什么不使用 SVG 格式,这样就不用为每个屏幕尺寸在项目中放置多个图像了。
  • @Amas:我不知道 SVG 格式的图像,会检查它们
  • 简单说明:Unlike raster formats seen in JPG, GIF, and PNG, an SVG image remains crisp and clear at any resolution or size.

标签: android react-native react-native-android react-native-ios


【解决方案1】:

您可以通过platform单独使用。

对于Android assets 文件夹中的图像,使用asset:/ 方案:

<Image source={{ uri: 'asset:/app_icon.png' }} style={{ width: 40, height: 40 }} />
var icon = Platform.OS === 'ios' ? require('./my-icon-active.png') : require('asset:/my-icon-inactive.png');
<Image source={icon} />;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-02
    • 2017-12-28
    • 2013-08-06
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    相关资源
    最近更新 更多