I have a custom view that I'm trying to use in a vertical orientation with a textview/button combo (stuck in a horizontal LinearLayout) positioned below it on the screen. Currently my layout looks like this:
<com.company.widgets.MyCustomView
android:id="@+id/custom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_weight="0.0" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:layout_weight="1.0"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:layout_marginLeft="15dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:text="foobar" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:text="foobar" />
</LinearLayout>
In my custom view I've overridden onMeasure() and onSizeChanged(). I take pains to ensure that my view's size doesn't exceed the measureSpec (for onMeasure) or the width/height values (for onSizeChanged) that it is passed. However, when my activity is laid out, the values passed to these two methods represent "the whole vertical height of the screen".
Consequently my custom view ends up making itself as tall as it wants to be and the button/textview make themselves "as tall as they need to be" (wrap_content). When these two heights exceed the height of the screen, the bottom portion of the custom view is drawn behind the button/textview.
My question: how should I modify the layout so that my custom view's onMeasure() and/or onSizeChanged() methods are passed a shorter height value? I'd like them to receive a value representing "screen height - height of the textview/button".
Note: if I change the layout so that the textview/button are positioned above the custom view, the height value I'm passed is correct (i.e. smaller than screen height).