将Imageview缩放到全屏而不会拉伸位图。

时间:2014-10-13 16:04:50

标签: android bitmap imageview

当位图为240 * 240大小时,如何将ImageView缩放到设备的全屏。  我使用了以下代码。

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/layoutBGColor"
     android:clickable="true" >

<ImageView
    android:id="@+id/fullImage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY" />

 ------
ImageView  iv = (ImageView)findViewById(R.id.fullImage);
iv..setImageBitmap(bitmap);

位图是240 * 240,位图看起来是stratched。我用谷歌搜索了thisthis,但没有一个有效。请建议我如何在没有划痕的情况下全屏设置位图。

1 个答案:

答案 0 :(得分:0)

显然,由于图像尺寸小于屏幕尺寸,因此绝对会拉伸。如果您在谈论在拉伸图像时保持纵横比,请尝试以下代码。

<ImageView
    android:id="@+id/fullImage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter" />

诀窍是使用android:adjustViewBounds