【问题标题】:XXHDPI images look different on different devices with similar resolutionsXXHDPI 图像在具有相似分辨率的不同设备上看起来不同
【发布时间】:2016-01-19 15:28:36
【问题描述】:

我有一张图片用作相对布局的背景。制作图像时要牢记 XXHDPI 设备 (1080x1920) 的分辨率。当我在带有物理导航按钮(如 Samsung S4)的设备中运行应用程序时,图像看起来很棒,但当我在具有屏幕导航按钮的设备(如 Nexus)中运行应用程序时,相同的图像看起来会被压扁5.

我正在附加输出:

三星 S4 中的图像很好

图片在 Nexus 5 中看起来被压扁了

使用该图片的布局源代码

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             tools:context="com.studystory.onboarding.screenOne">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:background="@drawable/help_screen_one">





    </RelativeLayout>
</FrameLayout>

为什么两个具有相似分辨率的设备的输出不同?我需要做什么才能使图像在两个设备中看起来相似?

【问题讨论】:

  • "XXHDPI 设备的分辨率 (1080x1920)" -- 密度不是分辨率。 1920x1080 设备可以具有任何密度,具体取决于其物理屏幕尺寸。除此之外,您的问题可能与您的布局资源或您用于组装此 UI 的任何内容有关。
  • @CommonsWare 我需要做什么来解决这个问题?我不是设计师,对分辨率和密度不太了解。如果您可以提出更改建议,我会要求设计师以相同的方式实现它。
  • 您需要设置缩放以保持纵横比,并且当比例有点偏离时,图像可以超出屏幕
  • @SamiKuhmonen 怎么做?可以在代码中完成吗?我会要求设计师为此做些什么吗?
  • 是的,它是在布局代码中完成的。图像控件将对其进行设置,不要记住它们。

标签: android xml image resolution


【解决方案1】:

我已经通过修改布局解决了这个问题。我在布局内使用了一个 imageview 来显示图像。

示例代码

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.studystory.onboarding.screenFive">

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView"
        android:src="@drawable/help_screen_five"
        android:scaleType="centerCrop"/>
</RelativeLayout>
</FrameLayout>

android:scaleType="centerCrop" 成功了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多