Does android:scaleType="fitCenter" only work with fix Layout_width and Layout_height attributes?

OneWorld picture OneWorld · Sep 24, 2010 · Viewed 29.7k times · Source

I use Layout_width="fill_parent" and Layout_height="wrap content". If an image is bigger than the ImageView, it will be downscaled perfectly.

However, I never got it working to upscale smaller images. I tried any combination of ScaleType and "AdjustViewBounds": it always stays in its own size in the middle of the image view. Here is the code...

 <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>

Answer

Jack L picture Jack L · Dec 3, 2012

I just found a way to make it work.

This works in 2.1(AVD) & 4.1.2(device)

<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>