2

How do I display an image with the following configuration in Android?

  • Retain original aspect ratio (the image can be scaled, but not stretched)
  • Fill the width of the parent
  • Aligned to the bottom of the parent

The following does not work:

<ImageView
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:layout_alignParentBottom="true"
android:src="@drawable/background" />

Using the above xml the ImageView takes the width of the parent, but the image inside the ImageView does not.

hpique
  • 119,096
  • 131
  • 338
  • 476

1 Answers1

0

Some points. If you want to manteint aspect ratio instead of fitCenter you should try centerInside:

Scale the image uniformly (maintain the image's aspect ratio) so
that both dimensions (width and height) of the image will be equal
to or less than the corresponding dimension of the view (minus padding). 

Remember that devices using your application might have different screen sizes. If your background image is something that can be stretched I would recommend you try a NinePatchDrawable

Macarse
  • 91,829
  • 44
  • 175
  • 230