如何在android中将一组按钮对齐到屏幕底部

2024-02-25

在我的布局中有四个部分,分别是标题、可编辑控件、列表和一组按钮。我想将按钮保留在屏幕底部。我对布局做了太多更改,迫使按钮位于底部。但什么也没发生。请提供说明来制作我需要的东西。我也发布布局

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!--  heading for basic settings -->
        <TextView
            android:id="@+id/setup_macroheading"
            style="@style/txtHeading" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="20dp"/>

         <!--  macro name -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="left|center_vertical"
                android:layout_weight="1"
                android:textColor="@color/white"                    
                android:text="Macro Name"/>

            <EditText
                android:id="@+id/setup_macroname"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight="1"
                android:maxLength="12"
                android:inputType="textCapCharacters"
                android:singleLine="true"/>                 
        </LinearLayout>

        <View
            android:layout_width="fill_parent"
            android:layout_height="20dp"/>

        <ListView
            android:id="@+id/lvMacroList"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
        />

        <!-- Save & Cancel button -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:layout_gravity="bottom"
            android:orientation="horizontal">

            <Button
                android:id="@+id/setup_macroSavebtn"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_weight="1"
                android:onClick="onSaveButtonClick"
                android:text="Save"/>

            <Button
                android:id="@+id/setup_macroCancelbtn"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight="1"
                android:onClick="onCancelButtonClick"
                android:text="Cancel"/>         
        </LinearLayout>
    </LinearLayout>
  </ScrollView>

将包含按钮的 LinearLayout 的 Parent 设置为相对,并将包含两个按钮的线性布局的属性设置为 android:layout_alignParentBottom="true"。您还可以将线性布局的重力设置为底部。

尝试这个:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

      <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <!--  heading for basic settings -->
    <TextView
        android:id="@+id/setup_macroheading"
        style="@style/txtHeading" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="20dp"/>

     <!--  macro name -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical"
            android:layout_weight="1"
            android:textColor="@color/white"                    
            android:text="Macro Name"/>

        <EditText
            android:id="@+id/setup_macroname"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:maxLength="12"
            android:inputType="textCapCharacters"
            android:singleLine="true"/>                 
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="20dp"/>

    <ListView
        android:id="@+id/lvMacroList"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
    />
</LinearLayout>
    <!-- Save & Cancel button -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:orientation="horizontal"
        android:paddingLeft="20dp"
        android:paddingRight="20dp" >

        <Button
            android:id="@+id/setup_macroSavebtn"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_weight="1"
            android:onClick="onSaveButtonClick"
            android:text="Save"/>

        <Button
            android:id="@+id/setup_macroCancelbtn"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:onClick="onCancelButtonClick"
            android:text="Cancel"/>         
    </LinearLayout>
</RelativeLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在android中将一组按钮对齐到屏幕底部 的相关文章

随机推荐

  • iPhone应用程序生命周期中的最后一个功能是什么

    在我的应用程序关闭之前 我必须从网络服务中注销用户 我找不到应用程序死亡之前调用的最后一个函数 void LogoutUser int userId GlobalData sharedMySingleton getUserId NSStri
  • 是否有一个格式说明符始终表示带有 _tprintf 的字符字符串?

    当您在 Windows 上构建应用程序时 使用TCHAR支持 s in tprintf means char Ansi 构建的字符串和wchar t 对于 Unicode 构建 同时 S意思是相反 但是是否有任何格式说明符总是意味着char
  • Docker 原生 Windows 支持吗?

    我很难找到这方面的信息 我在某处看到消息称 Docker 现在已原生集成到 Windows 中 那么显然这意味着它们不是 Linux 容器 而是某种 Windows 容器 有人有这方面的更多信息吗 由于许多 Docker 收购 出现了重大更
  • Docker上下文如何使用特定的ssh密钥

    我想使用 docker 上下文通过 ssh 联系服务器 我的本地有许多不同的 ssh 密钥 如何告诉上下文使用特定的键 我试过了 docker context create test docker host ssh
  • Swagger 未找到 ApiVersion ed 操作

    我正在 ASP NET Core 中构建 Web API 并尝试多个版本 我正在按照以下说明为每个版本创建 Swagger 文档 https github com domaindrivendev Swashbuckle AspNetCore
  • 如何在我的map/reduce函数中调用mongodb?这是一个好的做法吗?

    我想知道是否 首先 是否可以在我的map reduce函数中使用mongodb函数 例如 function foo db myCollection find id ObjectId 4ee235ce002c62f393000008 prin
  • php中的jquery ajax停止重新加载页面[重复]

    这个问题在这里已经有答案了 当我单击书籍链接时 他重新加载页面并对列进行排序 我想使用ajax停止重新加载 如何 这是我在这个过程中的职责 这个 getBook 函数 public function getBooks start 0 lim
  • 用内置的角度动画替换 jQuery 动画

    给定这个模板 div h2 TEST headline Title h2 div 以及以下指令 我如何将该指令更改为replace the jquery内置淡入淡出angular动画 我要求文本淡出 替换 然后淡入 newman direc
  • 默认情况下 ASP.NET 4.0 代码在哪个帐户中执行?

    比方说 我有一个访问 读 写 文件系统 应用程序内的文件 Active Directory 和 SQL Server 数据库的应用程序 我需要授予该帐户权限 以便他访问这些内容 应用程序池标识为 IIS APPPOOL ASP NET v4
  • Android 4.0 c2dm问题

    当我使用 android c2dm 将通知推送到我的设备时 我遇到了一个奇怪的问题 如果我使用 管理应用程序 gt 我的应用程序 gt 强制停止 关闭应用程序 并且尝试向我的设备发送推送 则它不起作用 它适用于我所有其他 Android 版
  • 检查数组的递归情况

    在 PHP 中检查数组是否递归的最佳方法是什么 给出以下代码 来自PHP 手册 http www php net manual en language types array php 73936 print r 将显示递归当到了第三个的时候
  • 如何使用 QT 设置 PATH 变量?

    如何使用 QT 4 8 获取和设置 PATH 变量 我知道我可以使用 STL 中的 getenv 获取 PATH 变量值 但不知道如何使用 STL 或任何基于 Qt 的方法设置它 如果 QT 有它的功能 我想了解并使用它 而不是去使用 Wi
  • SQL Server 2008 将地理点保存为十六进制

    我已将轨迹记录到文本文件中 现在我想将其作为点类型插入 SQL Server 2008 R2 数据库的表中 我使用 OpenRowSet 读取文本文件并将每一行插入临时表中 然后我解析每一行并将正确的值插入到真实表中 文件中的每一行如下所示
  • 使用 Collections.sort 对自定义类数组列表字符串进行排序

    我试图通过声明我自己的匿名比较器来使用 Collections sort 对我的自定义类数组列表进行排序 但排序并没有按预期工作 我的代码是 Collections sort arrlstContacts new Comparator
  • nametuple — 同一定义中不同类型名称的应用

    蟒蛇namedtuple工厂函数允许指定它创建的子类的名称两次 第一次在声明的左侧 然后作为函数的第一个参数 IPython 1 0 0 Python 3 3 1 In 1 from collections import namedtupl
  • ItemNotMappedException: XYZ 没有工作文件夹映射

    我通过 VersionControlOnNonFatalError Eventhandler 收到异常 内容如下 C SqlWorkspace 没有工作文件夹映射 我的机器上确实有该映射 因此 我想知道出了什么问题 该错误是在 worksp
  • 使用派生较多的参数调用重载函数的更好方法,传入派生较少的类型

    我有 16 个带有两个参数的方法 这两个参数中的每一个都可以是 插入 或 删除 它们都实现了 IFragment 我还有四个像这样的辅助函数 static IFragment IntroduceAntecedent IFragment on
  • Laravel - 如何在会话中存储多个对象

    目前 这仅在会话中存储名字 我需要在会话中存储所选用户的一些其他对象 例如级别和城市 我怎样才能做到这一点 id username first name last name level city 1 john John Parks 1 Lo
  • 如果选择了特定的选择选项值,则显示 div

    如果用户从选择下拉列表中选择特定选项值 我会尝试显示 div Example 选择下拉列表包含从数据库获取的动态名称以及列表底部称为 Admin 的静态或永久名称 如果用户选择不是 Admin 的选项 则会显示包含特定表单元素的 div 否
  • 如何在android中将一组按钮对齐到屏幕底部

    在我的布局中有四个部分 分别是标题 可编辑控件 列表和一组按钮 我想将按钮保留在屏幕底部 我对布局做了太多更改 迫使按钮位于底部 但什么也没发生 请提供说明来制作我需要的东西 我也发布布局