22

我使用 Layout_width="fill_parent" 和Layout_height="wrap content"。如果图像大于 ImageView,它将被完美地缩小。

然而,我从来没有得到它的工作来放大较小的图像。我尝试了ScaleType和“AdjustViewBounds”的任意组合:它始终在图像视图的中间保持自己的大小。这是代码...

 <LinearLayout
        android:id="@+id/LinearLayout02"
        android:layout_height="wrap_content"
        android:background="@drawable/content_bg"
        android:orientation="vertical"
        android:padding="5dp"
        android:layout_width="fill_parent"
        android:layout_marginLeft="1px">
        <ImageView
          android:layout_height="wrap_content"
          android:src="@drawable/test"
          android:id="@+id/ImageViewTest"
          android:layout_width="fill_parent"
          android:adjustViewBounds="true"
          android:scaleType="center"></ImageView>
</LinearLayout>
4

4 回答 4

9

我刚刚找到了一种让它工作的方法。

这适用于 2.1(AVD)和 4.1.2(设备)

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

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

</LinearLayout>
于 2012-12-03T06:29:30.013 回答
5
<LinearLayout
    android:layout_height="wrap_content"

使用内部图像的原始大小。

尝试更大的东西或 fill_parent

于 2011-09-08T15:18:46.023 回答
2

使用android:scaleType="FIT_START"or android:scaleType="FIT_END", 计算将保持原始 src 纵横比的比例,但也将确保 src 完全适合 dst(来自 GoogleDev)。

更多信息:

http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

于 2011-11-07T13:16:32.577 回答
1

如果尺寸很小,添加 android:scaleType="fitXY"到您的 ImageView 应该会拉伸图像。

于 2010-09-24T08:51:44.920 回答