我试图防止 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 的高度的情况下阻止这种情况发生?
我的所有 View 都使用了 android:layout_height="wrap_content"
。
这不是应该自动分配 View 的高度以适应屏幕的高度吗?
(想要包含图片,但我的代表还不够高 (-_-))
最佳答案
我今天要解决这个问题的方法是使用 RelativeLayout
作为基础。将两个 LinearLayout
分别锚定到 RelLayout 的顶部和底部。然后我会插入 ScrollView
但我会确保按如下方式设置它的布局属性:
android:layout_below="topLinearLayout"
android:layout_above="bottomLinearLayout"
关于android - 防止 ScrollView 占用太多高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8679243/