How do I display this image in Android?
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"
a开发者_运维知识库ndroid: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.
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
精彩评论