Wednesday, July 13, 2011

[android-developers] android:layout_above does not work while android:layout_below does

I see a red rectangle above a blue rectangle with this layout using
"layout_below" on the lower blue rectangle.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View android:id="@+id/id_red_view"
android:layout_width="200dip"
android:layout_height="100dip"
android:background="#ffff0000" />
<View android:id="@+id/id_blue_view"
android:layout_width="200dip"
android:layout_height="100dip"
android:layout_below="@+id/id_red_view"
android:background="#ff0000ff" />
</RelativeLayout>

However, with this layout using "layout_above" on the upper red
rectangle, I see just the blue rectangle. HierarchyViewer shows that
the red rectangle *is* above the blue rectangle, but its getHeight()
is 0.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View android:id="@+id/id_red_view"
android:layout_width="200dip"
android:layout_height="100dip"
android:layout_above="@+id/id_blue_view"
android:background="#ffff0000" />
<View android:id="@+id/id_blue_view"
android:layout_width="200dip"
android:layout_height="100dip"
android:background="#ff0000ff" />
</RelativeLayout>

Setting android:minHeight on the red rectangle does not fix the
problem. I tried swapping the order of the views to avoid a forward
reference, but that does not help either. Any idea why this is
happening? Is layout_above just broken?

Thanks,
Shri

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment