Positioning an image inside an ImageView with max height and max width set
Posted
by andern
on Stack Overflow
See other posts from Stack Overflow
or by andern
Published on 2010-05-04T01:23:59Z
Indexed on
2010/05/04
1:38 UTC
Read the original article
Hit count: 553
I have an ImageView
with max height and max width both set to 100
. The figure below is clearly not a square, but you can use your imagination ;)
Figure 1:
+----------------------------------------------+
¦ ImageView +--------------+ ¦
¦ ¦ ¦ ¦
¦ ¦ Actual image ¦ ¦
¦ ¦ ¦ ¦
¦ ¦ ¦ ¦
¦ ¦ ¦ ¦
¦ +--------------+ ¦
+----------------------------------------------+
Anyway, If I try to set a BitMap
to the ImageView
that does not have a ratio of 1:1, the image is positioned like pictured in Figure 1. What I want is for the picture to be placed to the left inside the ImageView
like pictured in Figure 2 below.
Figure 2:
+----------------------------------------------+
¦--------------+ ¦
¦ ¦ ¦
¦ Actual image ¦ ¦
¦ ¦ ¦
¦ ¦ ¦
¦ ¦ ¦
¦--------------+ ¦
+----------------------------------------------+
You can see my ImageView in XML below. maxHeight
, maxWidth
and adjustViewBounds
are set during runtime.
<ImageView android:id="@+id/someImage"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textName"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingRight="4dp"
/>
This is in a RelativeLayout
if it makes any difference.
© Stack Overflow or respective owner