java - 拆分滚动视图,使其拉伸一半的屏幕,但它忽略了布局权重
问题描述
我正在尝试创建一个显示在屏幕上半部分的垂直滚动视图,下半部分将有几个按钮。
我有一个垂直线性布局,其中有两个垂直线性布局(顶部包含滚动视图),并将两个线性布局中的每一个设置为布局权重为 1,但滚动视图无论如何都会延伸超过页面的一半。
<LinearLayout
android:id="@+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="@drawable/b_whitetrans4">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fadeScrollbars="false"
android:scrollbarThumbVertical="@android:color/holo_red_dark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:orientation="vertical">
<TextView
android:id="@+id/settingtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="asdfasdfasdfasdfasdf"
android:textColor="@android:color/white"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:id="@+id/buttonlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
奇怪的是,滚动视图并没有一直拉伸以显示所有内容,但它肯定超过了屏幕的一半。这就是发生的事情: https ://www.screencast.com/t/VPHJwPhpLyb
解决方案
将顶部 LinearLayout 的高度设置为match_parent
并删除layout_weight
下部的属性。
推荐阅读
- asp.net-core - .net核心应用程序在引入Form标签时抛出异常
- c++ - 链接器错误:“针对符号 `xmlFree' 重新定位 R_X86_64_PC32 ... 使用 -fPIC 重新编译”但有问题的库已经使用 -fPIC 进行了编译
- squashfs - rauc 无法挂载 .raucb 文件
- react-native - 反应原生社区 datetimepicker 没有给我一个日期戳
- python-3.x - 有没有办法在 Python 中打印错误消息?
- c# - 如何在循环中运行进程并等待它完成然后在 C# 中再次运行它而不冻结 GUI
- c++ - 我收到一条错误消息,说只有虚拟功能可以标记为覆盖
- python - 如何在没有副作用的情况下腌制和解封?
- javascript - 如何在Javascript中将数组值作为对象键传递
- outlook - Microsoft 图形 API - 空的 bccRecipients 列表