我的布局的一部分应该有两个组件:顶部的滚动视图和底部的地图视图。两个视图的大小应该正好是父视图的一半。
我有父级的大小(我在已经有大小的时候切换到这个布局),但是我不知道如何定义最大大小。此外,我认为有一种解决方案不需要定义大小;例如,通过使用类似于Swing样式的网格布局,或者在某个地方定义权重,但我没有找到任何听起来可行的方法。
我目前的方法是这样的,它定义了最小的大小,当滚动视图超过父视图一半的高度时,最小的大小就会明显地分开:
布局(父级是线性布局):
<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>
在我切换到代码之后(totalwidth是父级的宽度,viewheight是父级高度的一半):
LinearLayout.LayoutParams lp =
new LinearLayout.LayoutParams(totalWidth, viewHeight);
scrollView.setLayoutParams(lp);