Consider the following layout:
A bit of testing (subclassing View
, overriding onMeasure()
and onLayout()
) reveals that FrameLayout
is broken in this respect in older Android versions.
Since FrameLayout
fails to pass its own height down the hierarchy in this scenario (the View
will always see 0
both with onMeasure()
and onLayout()
) there is no obvious way to work around this problem by subclassing.
The question then was, is there another way to overlay the two views which Android 2.2 aka API 8 can handle correctly.
And alas, there is. The same can be achieved with a RelativeLayout
, which involves much more overhead of course, though the actual increase in rendering effort should be limited.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg1" >
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="@+id/item"
android:layout_alignBottom="@+id/item"
android:background="@drawable/bg2" />
<LinearLayout
android:id="@+id/item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</RelativeLayout>