Alex Rivera | Logout

Positioning an image inside an ImageView with max height and max width set

Asked 2010-05-04T01:23:59.647
16

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.

Edit
Report

1 Answer

1

I use:

android:scaleType="fitCenter"

documented here. Good luck!

EDIT: My bad, I didn't realize you were centering an image in an ImageView (my first reading I thought you were having trouble centering the ImageView within another View). Now I'm not so sure, but you could look at ScaleType anyways ^_-

answered 2010-05-04T02:58:37.083

Your Answer