【发布时间】:2012-01-30 13:02:27
【问题描述】:
我试图防止 ScrollView 在屏幕底部占用太多空间,因为它使我的两个按钮无法显示。我也不想手动设置 ScrollView 的高度。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
...
android:orientation="horizontal">
<Button .../>
<TextView .../>
<Button .../>
</LinearLayout>
<ScrollView
android:layout_width="math_parent"
android:layout_height="wrap_content">
<ImageView .../>
<ImageView .../>
<ImageView .../>
</ScrollView>
<LinearLayout
...
android:orientation="horizontal">
<Button .../>
<Button .../>
</LinearLayout>
</LinearLayout>
这是我的布局的通用版本。发生的情况是 ScrollView 一直延伸到屏幕底部,无论其中有多少项目。这会导致屏幕底部的两个按钮不可见。
如何在不手动设置 ScrollView 高度的情况下阻止这种情况发生?
我的所有观点都使用了android:layout_height="wrap_content"。
这不是应该自动分配视图的高度以适应屏幕的高度吗?
(想要包含图片,但我的声望还不够高(-_-))
【问题讨论】:
-
切换到RelativeLayout 作为您的根布局可能是个好主意。它应该为您提供工具,让 ScrollView 保持在视图的中心区域内,而无需自己明确计算其高度。
-
感谢您的评论。从那以后,我实施了一个不同的解决方案,但在此过程中我学到了更多的东西,我相信您的实施将最适合我想做的事情。 RelativeLayout 允许我将按钮锚定到屏幕底部,然后将所有其他 UI 对象放置在屏幕顶部和按钮之间。
-
你的 ScrollView 应该有不超过一个孩子。不知道这是否是您的问题的原因。
标签: android height scrollview