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?
views:
613answers:
3When 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.
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.
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.