Android layout - alignment issue with ImageView

Viewed 70280

I'm trying to put an image at the top left of a LinearLayout, but with the image border and padding taking up the whole of the width of the window.

If I try the XML below, I get my image with its border and a white background across the whole width of the page, except that the image ends up centered, and doesn't move to the left.

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:src="@drawable/banner"
    android:background="@android:color/white"
    android:padding="@dimen/d_8px"
/>

Is there some attribute that I've not yet discovered that forces the image to be left aligned within the ImageView when the layout_width is set to fill_parent?

In the meantime, I've worked around this by dropping the ImageView inside another LinearLayout and dropping an empty TextView to its right that takes up the rest of the horizontal space.

2 Answers

I was having a similar problem, to which you replied earlier today. Is this on "screen design" viewer provided by the Eclipse plugin side-by-side with the XML editor, or are you encountering the alignment problems when actually running the app? If the former, that appers to be a bug in the plugin, if the latter, try adding:

android:scaleType="fitStart"

From the documentation I've read, that seems to be the closest to what you need.

Related