【发布时间】:2010-10-17 23:06:33
【问题描述】:
我的布局的一部分应该有两个组件:顶部的 ScrollView 和底部的 MapView。两个视图的大小都应该是父视图的一半。
我有父级的大小(当我已经有大小时,我正在切换到这个布局),但我不知道如何定义最大大小。此外,我认为有一个不需要定义大小的解决方案;例如,通过类似 Swing 风格的 GridLayout 或在某处定义权重,但我还没有找到任何听起来可行的方法。
我目前的方法是这里,它定义了最小尺寸,一旦 ScrollView 增长超过父级高度的一半,它显然会崩溃:
布局(父级是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>
还有代码,在我切换到它之后(totalWidth 是父级的宽度,viewHeight 是父级的一半高度):
LinearLayout.LayoutParams lp =
new LinearLayout.LayoutParams(totalWidth, viewHeight);
scrollView.setLayoutParams(lp);
【问题讨论】: