One part of my layout is supposed to have two components: A ScrollView on top, and a MapView on the bottom. Both views should be exactly half the size of the parent.
I have the size of the parent (I’m switching to this layout at a point when I already have the size), but I don’t know how to define the maximum size. Besides, I figure there is a solution that doesn’t require defining the size; for example by having something like a Swing-style GridLayout, or defining a weight somewhere, but I haven’t found anything that sounds like it would work.
My current approach is this here, which defines the minimum size, which obviously falls apart as soon as the ScrollView grows beyond half the height of the parent:
The layout (the parent is a LinearLayout):
<LinearLayout
android:id="@+id/result_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
>
<ScrollView
android:id="@+id/result_scroll"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/result"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:paddingRight="?android:attr/scrollbarSize"
android:orientation="vertical"
/>
</ScrollView>
<view class="com.google.android.maps.MapView"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
And the code, after I switch to it (totalWidth being the width of the parent, viewHeight half the height of the parent):
LinearLayout.LayoutParams lp =
new LinearLayout.LayoutParams(totalWidth, viewHeight);
scrollView.setLayoutParams(lp);
Put them in a
LinearLayout. Set the the height of each to0px. Set the weight of each to1.For example:
If you don’t tell it how big it is explicitly (“defining the size”) or implicitly (“defining a weight”), how are you expecting to know it is supposed to be “exactly half the size of the parent”?