0

I am trying to scale an image specifying only the width I want. The height would be scaled in a way that the aspect ratio is preserved. The image I am using is big enough to cover the whole screen. The code I am trying looks like this:

<ImageView android:src="@drawable/logo"
        android:layout_width="100sp" android:id="@+id/imageView1"
        android:layout_height="wrap_content" android:scaleType="centerInside"/>

If I use "fitXY" the image doesnt preserve the aspect ratio and when I use "centerInside" the image is not scaled.. Any idea?

Thank you in advance.

jesbomar
  • 43
  • 1
  • 6
  • Solution in a comment of answer 1 – jesbomar Jun 20 '11 at 18:07
  • have a look at this: http://stackoverflow.com/questions/6410364/how-to-scale-bitmap-to-screen-size/6410419#6410419 –  Jun 20 '11 at 17:44
  • 3
    I already got it!! You have to use the properties android:adjustViewBounds="true" and android:scaleType="fitXY". So the code looks like this: Regards! – jesbomar Jun 20 '11 at 17:45

1 Answers1

0

Jesbomar's solution with pretty formatting:

<ImageView 
    android:src="@drawable/logo" 
    android:adjustViewBounds="true" 
    android:layout_width="100sp" 
    android:id="@+id/imageView1" 
    android:layout_height="wrap_content" 
    android:scaleType="centerInside" 
    /> 

I prefer scaleType="centerInside" to "scaleXY" to make the image as big as possible without changing the aspect ratio or cropping any part of it.

Thanks for coming back with your solution jesbomar, it was very helpful.

Ethan_AI
  • 1,049
  • 2
  • 13
  • 20