繁体   English   中英

如何计算特定Android设备的初始屏幕的图像大小

[英]How to calculate image size for splash screen of a particular android device

我将单个图像(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设备上运行的唯一方法。

非常感谢

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"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM