tags:

views:

10210

answers:

3

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 mean-time 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.

+7  A: 

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.

executor21
that does indeed seem to do the trick. As does not using an ImageView at all and using the drawableLeft attribute of a TextView :)
Alnitak
hey @executor21 . thanx for such answer.. it works for me....
PM - Paresh Mayani
Thanks... worked great and saved me the time of asking this question myself
iandisme
A: 

Hey,executor thanks a lot for that tip of using scaleType attr, it worked good for me. My ImageView was getting layed out in the center and I tried all the attributes related to it positioning, none worked except the one above.

Rohan

ROHAN
A: 

Oh Man you are great this really works for me too.

adnan