【问题标题】:How to calculate image size for splash screen of a particular android device如何计算特定 android 设备启动画面的图像大小
【发布时间】:2016-08-26 12:58:58
【问题描述】:

我设置单张图片(640x960)如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.imagetest.MainActivity"
    tools:showIn="@layout/activity_main">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/launch_image"
        android:scaleType="center"/>
</RelativeLayout>

请注意 scaleType 是“中心”,根据文档,这意味着没有缩放。在 Nexus 5x 上运行时,此图像看起来比屏幕大很多,并且只显示了一部分。

我读到了 android 不直接使用分辨率。那么问题是如何计算应该适合特定android设备屏幕而不缩放的图像的大小。

我了解九个补丁图像可用于创建不会扭曲不应缩放的图像部分的启动图像。这个问题部分是为了让我自己更好地了解图像像素与实际设备屏幕的关系,以及是否使用九补丁图像是保证启动图像适用于任何屏幕尺寸的 android 设备的唯一方法。

非常感谢

【问题讨论】:

  • 您将此图像放在哪个密度文件夹中?
  • 好像您只将图像放在一个文件夹中,例如xhdpi, android 会根据它的密度重新缩放这个图像。因此,图像在 hdpi 屏幕上看起来会更小,而在 xxhdpi 和 xxxhdpi 屏幕上看起来会更大。
  • 好问题。我只有可绘制的图像。为什么这会让 640x960 的图像看起来比 Nexus 5x 的屏幕大?

标签: android pixel dpi splash-screen


【解决方案1】:

scaleType centerInside 应该可以解决问题,而无需在代码中进行计算

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/launch_image"
        android:scaleType="centerInside"/>

【讨论】:

  • 感谢 NathaZ,但部分问题是要了解为什么 640x960 图像在 Nexus 5x 上显示更大,屏幕分辨率为 1080x1920。我知道图像分辨率不能转化为屏幕分辨率。但我想了解这两者之间的关系。
  • 你为什么在启动画面上使用 app:layout_behavior?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-04
  • 2020-12-14
  • 2021-11-14
  • 2022-09-27
  • 1970-01-01
相关资源
最近更新 更多