不要在ImageView中拉伸图像

时间:2015-03-26 08:43:19

标签: android imageview

我想在ImageView中拉伸图像。我使用9path图像。这是我的代码:

<FrameLayout     
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="18dp">

    <ImageView
        android:id="@+id/glass_progress"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:src="@drawable/img"
        android:scaleType="fitXY"
        android:background="@color/white"/>
</FrameLayout

但是生成的图像没有拉伸(图像周围有白色背景)。为什么呢?

3 个答案:

答案 0 :(得分:0)

试试这个。不要设置固定高度。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
    >

<ImageView
        android:id="@+id/glass_progress"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:src="@drawable/img"
        android:scaleType="fitXY"
        android:background="@color/white"
        />
 </FraneLayout

答案 1 :(得分:0)

将match_parent更改为wrap_content ..

<ImageView
    android:id="@+id/glass_progress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:src="@drawable/img"
    android:scaleType="fitXY"
    android:background="@color/white"
    />

答案 2 :(得分:0)

这会将图像设置为背景

<ImageView
android:id="@+id/glass_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="@drawable/img"
/>

试试这个也将裁剪图像

<ImageView
    android:id="@+id/glass_progress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:src="@drawable/img"
    android:scaleType="centerCrop"
    android:background="@color/white"
    />
相关问题