【问题标题】:Stop imageview from stretching on certain devices停止 imageview 在某些设备上的拉伸
【发布时间】:2015-02-22 21:41:17
【问题描述】:

我有一个如下所示的活动 xml:

<LinearLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:orientation="vertical"
    android:baselineAligned="false">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:background="@drawable/top"
        />

    <ScrollView
                ....

这基本上在线性布局顶部显示了一个横幅,下面是一个滚动视图。我遇到的问题是图像在某些设备上被拉伸。源图像宽度为 1080px(在 drawable 和 drawable-xxhdpi 文件夹中),drawable-xhdpi 中为 720px,drawable-hdpi 中为 540px,drawable-mdpi 中为 480。

我是否忘记了什么或给了错误的宽度?顺便说一句,图像被垂直拉伸。

感谢您的帮助!

【问题讨论】:

    标签: android xml imageview android-drawable stretch


    【解决方案1】:

    您的图片尺寸错误。图像大小为 480dp 的正确比例是

    • mdpi 480px (x1)
    • hdpi 720px (x1.5)
    • xhdpi 960px (x2)
    • xxhdpi 1440px (x3)

    另外,drawable 文件夹中也不需要有图片,Android 会从列出的列表中选择最好的一个。 有关更多信息,请参阅 this 文档

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-15
      • 1970-01-01
      • 2019-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多