android - 防止 ScrollView 占用太多高度

标签 android height scrollview

我试图防止 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/

相关文章:

java - 我有文字转语音功能,显示按钮文本,但所有按钮都显示第一个按钮的文本

java - 团结 : CommandInvokationFailure: Failed to recompile android resource files

android - Google Cast v3 Mini Controller 在 CoordinatorLayout 中使用时 float 到顶部

html - CSS 两列 100% 宽度和相同的高度(正方形)

android - 如何使用android :layout_width ="wrap_content"?获取以像素为单位的宽度

jquery - 如何使用更少的代码使用填充/边距值计算元素的宽度和高度?

ios - Swift:如何使 ScrollView 与 PageControl 一起使用?

objective-c - 如何在滚动条中包含其他控件?

Android - 水平 ScrollView 中的线性布局不起作用

java - 如何创建具有自动平移和缩放功能的 Android ImageView?