views:

613

answers:

3

When I use a RelativeLayout with either fill_parent or wrap_content as height and an element which specifies: android:layout_alignParentBottom="true" it is ignored and it is aligned at the top. Setting the height of the RelativeLayout to an explicit value makes it work. Any clues?

+2  A: 

When you inflate the layout, use inflate(R.layout.whatever, parent, false), where parent is the ListView. If you don't do that (e.g., you pass null for the parent), RelativeLayout gets strange in list rows.

CommonsWare
Still can't get it to work. I'm using CursorAdapter and in newView() I now have: View v = inflater.inflate(ROW_RESOURCE, postList, false);
alexanderblom
Here's a project from one my books that uses `RelativeLayouts` in rows: http://github.com/commonsguy/cw-advandroid/tree/master/Introspection/Launchalot/ -- see if that gives you any clues as to where things may be going wrong for you.
CommonsWare
Seems to be this: http://code.google.com/p/android/issues/detail?id=1394. Not fixed on 1.6. Setting a fixed height is not really an option as the height needs to be variable. Any good workarounds? Or am I forced to create may own custom layout ;C
alexanderblom
Can you achieve your visual goal with nested `LinearLayouts`?
CommonsWare
Not really, too complex. I'm trying to wrap the bottom aligned view in different layouts now to see if I can work around it. Might go to sleep and continue tomorrow instead tho :)
alexanderblom
A: 

This seems to be a bug in Android itself, see http://code.google.com/p/android/issues/detail?id=1394.

I worked around it by wrapping my RelativeLayout in a FrameLayout and putting my bottom aligned view as a children of the FrameLayout with android:layout_gravity="bottom". This hinders you from referencing it from within the RelativeLayout so you'll have to work around that (for example using margins).

If anyone has a better workaround, please share.

alexanderblom
A: 

I was able to get the proper alignment by specifying the problematic TextView with:

android:id="@+id/must_be_bottom_left"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_below="@id/xxx"

where "xxx" was the id of a TextView that has android:layout_below="@id/yyy"

and "yyy" is a TextView that is always above both "xxx" and "must_be_bottom_left".

The contents of my list items can vary so that sometimes the "xxx" TextView is View.GONE, but even then the layout works as expected.

I don't know how fragile or merely seredipidous this work-around is. I am using Android 1.6 and I haven't tested it for forward compatability.

Lou