ScrollView 和 LinearLayout 的困难

2024-05-14

我正在尝试制作一个 Android 布局:垂直 LinearLayout 内有 3 个组件。中心组件是一个ScrollView其中包含一个TextView。当。。。的时候TextView包含大量文本(超出了屏幕所能容纳的范围),ScrollView一直增长到屏幕底部,显示滚动条,并推送最后一个组件,aLinearLayout with a Button里面,屏幕外。

如果里面的文字TextView在 - 的里面ScrollView足够短,屏幕底部的按钮位置完美。

我想要实现的布局是:

我编写的布局的 XML 是:

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="10dip"
            android:layout_marginBottom="10dip"
            android:text="Title />

    <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

        <TextView android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoLink="web"
                android:textColor="#FFFFFF"
                android:background="#444444"
                android:padding="10dip" />

    </ScrollView>

    <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">

        <LinearLayout
                android:orientation="horizontal"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

        <Button android:id="@+id/login_button"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_weight="1"
                android:text="@string/next_button"/>

    </LinearLayout>

</LinearLayout>

ScrollView是第二个视图对象,设置为wrap_content,比屏幕多。

我推荐一个相对布局。首先是顶部文本视图android:alignParentTop="true",底部 LinearLayout 接下来是android:alignParentBottom="true"以及 xml 中最后列出的滚动视图的值android:alignBelow="@id/whatYouCallTheHeader.

这将对齐屏幕底部的底部栏和顶部的标题,无论大小如何。然后,在放置页眉和页脚之后,滚动视图将有自己的位置。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ScrollView 和 LinearLayout 的困难 的相关文章

  • 如何使用 Android 版 Facebook 同步的联系人图片

    我的手机上安装了 Android 版 Facebook 它会自动将联系人列表中人员的 FB 个人资料图片同步到我的手机 我想在我访问的应用程序中使用这些图片ContactsContract PhoneLookup 我真的需要 Faceboo
  • ActionBarCompat 支持库 android:selectableItemBackground 不起作用

    我正在使用新的 ActionBarCompat 支持库 操作栏中的操作按钮在按下时应更改其背景 它适用于 Android 4 3 但不适用于 Gingerbread 在姜饼中 如果我按下按钮 它不会改变背景 我什至改变了选择器 它再次适用于
  • 相当于Android中的javax.swing.Timer

    有没有类似的东西javax swing Timer在安卓上 我知道如何创建自己的线程 但是有类似摆动计时器的东西吗 您可能正在寻找课程android os CountDownTimer http developer android com
  • 为网络和/或持久存储序列化 Android Bundle?

    我需要序列化一个全面的应用程序 游戏 状态 以便通过网络传输或保存到磁盘并在以后检索 当然 捆绑包用于在多个用例中保存 恢复状态 因此使用它们将是理想的选择 但是 由于某种原因 Bundle 不可序列化 寻找解决方案只发现了将 Bundle
  • 不使用 CookieManager 的 Android 会话 cookie

    我的应用程序进行多次网络调用以获得身份验证 我需要将此会话存储在 cookie 中 我想使用 Cookie Manager 但经过一些研究后 我发现它仅适用于 API 9 及更高版本 并且我的应用程序需要向后兼容 我使用 HTTPURLCo
  • Android 上的硬币识别

    我目前正在开发一个 Android 应用程序 它能够拍摄硬币的现有图像 或者使用内置摄像头扫描单个硬币 非常像 Google Goggles 我正在使用 Android 版 OpenCV 我的问题如下 什么方法最适合使用 OpenCV 在
  • 从Asynctask返回结果

    如果我的 Android 应用程序中有这个后台工作文件 并且它从我的数据库获取数据 我如何将字符串 结果 传递给另一个类 后台工作人员连接到我的服务器 然后使用 php 连接到数据库 public class BackgroundWorke
  • 注销时Firebase facebook按钮android身份验证

    我在我的 Android 应用程序中使用 firebase 并在 facebook SDK 中使用登录 我面临的唯一问题是 当我使用 facebook 登录然后注销时 facebook 登录按钮处于 注销 状态 当我单击它时 它会询问我是否
  • 在 Android 中关闭 Spinner 中的下拉菜单

    在 Android 中打开和关闭微调器时 我需要为箭头图标设置动画 打开微调器时我可以旋转箭头 我只是放了一个setOnTouchListener on the Spinner 当下拉菜单关闭或隐藏时 问题就来了 因为我不知道如何在该操作上
  • 来自外部 XML 的 Android 本地化

    是否可以使用从服务接收到的 XML 在运行时翻译 Android 应用程序 如果可能的话 请有人指出我正确的方向 谢谢 Warning 我读到的所有内容都表明 让您的应用程序更改语言不是一个好主意 因为 Android 框架不支持它 并且可
  • 如何在不改变的情况下将字符串转换为字节?

    我需要一个解决方案将字符串转换为字节数组而不需要像这样进行更改 Input String s Test Output String s Test byte b Test 当我使用 s getBytes 那么回复是 B 428b76b8 但我
  • Android - 内容值覆盖现有行

    我正在尝试使用插入值ContentValues 我已将 5 个值插入到 5 列中 运行应用程序后 我只有最后一组值的行ContentValues 前四组未插入 ContentValues cv new ContentValues cv pu
  • Android框架结构与MFC/Win32结构的比较?

    我为 Android 和 Windows 进行开发 使用 MFC 有时使用 win32 昨天我随意比较了这两个框架 它们显然非常非常不同 因此 Windows 开发与 Android 开发有很大不同 我想知道人们认为 Android 这样的
  • Android 将菜单项在操作栏中向左对齐

    我的应用程序中有一个操作栏 它显示我定义的菜单项res menu activity main xml 我的菜单项在操作栏上向右对齐 我希望它们左对齐 我为此找到的唯一解决方案使用了自定义操作栏 如下所示 将菜单项放置在 Honeycomb
  • onTouch 给出奇怪的触摸点 Android

    我正在做的事情非常简单 我以前做过 但现在它没有按我的预期运行 无论如何 让我简要解释一下我正在尝试做什么以及我得到了什么 设想 我有一个RelativeLayout其中一个ImageView已放置 现在我设置touchlistener像这
  • 使用 eclipse 配置mockito 时出现问题。给出错误:java.lang.verifyError

    当我将我的mockito库添加到类路径中 并使用一个简单的mockito示例进行测试时 我尝试使用模拟对象为函数add返回错误的值 我得到java lang verifyerror 以下是用于测试的代码 后面是 logcat Test pu
  • 如何手动添加Android Studio依赖

    我多次尝试向我的项目添加依赖项 但每次都会出现错误 我想添加它们的依赖项是 de hdodenhof circleimageview 1 3 0 and com github bumptech glide glide 3 6 1 所以我想下
  • TYPE_ACCELEROMETER 和 TYPE_LINEAR_ACCELERATION 传感器有什么区别?

    I think TYPE ACCELEROMETER显示设备加速 但是 我不明白什么时候应该使用TYPE LINEAR ACCELERATION 我需要计算移动设备的速度 哪种传感器适合此应用 另外 我读到TYPE LINEAR ACCEL
  • RecyclerView元素更新+异步网络调用

    我有一个按预期工作的回收视图 我的布局中有一个按钮可以填充列表 该按钮应该进行异步调用 根据结果 我更改按钮的外观 这一切都发生得很好 但是 当我单击按钮并快速向下滚动列表时 异步调用的结果会更新新视图的按钮 代替旧视图的视图 我该如何处理
  • 将 firebase 消息传递添加到 flutter android 项目时出现依赖错误

    我已将 firebase 消息传递添加到我的 Flutter 项目中 在 iOS 上运行良好 在 Android 上运行时出现错误 Android dependency androidx localbroadcastmanager loca

随机推荐