Android ImageView拉伸图像

Android ImageView stretches image

我已经搜寻了很多东西,似乎没有任何工作可以避免横幅拉伸。
我已经在drawabled文件夹中保存了横幅的多个实例。 图像的宽度为:

  • xxhdpi:1440px
  • xhdpi:960px
  • hdpi:720px
  • mdpi:480px

当我在屏幕宽度为1080px(例如nexus 5)的设备上运行应用程序时,图像将被拉伸。

我正在使用的布局是垂直的线性布局,横幅位于顶部的imageview中。
我尝试过更改scaleType,layout_width / height和adjustViewBounds属性,但是似乎没有任何效果。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<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"
    android:background="@drawable/smos_bg"
    android:padding="0dp">

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

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none"/>
</LinearLayout>

谢谢您的帮助!


尝试这个:

1
2
3
4
5
6
7
 <ImageView
    android:id="@+id/imageId"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:src="@drawable/top">      
</ImageView>