Positioning an image inside an ImageView width max height and max width set
- by andern
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.