android - 试图在 Android 中将按钮推到线性布局的底部

标签 android android-layout android-linearlayout android-button

我知道这可以通过使用相对布局很容易地完成,但我觉得我正在做的是正确的并且应该通过线性布局本身给我想要的结果。但出于某种原因,当我在运行 Android JB 4.1.2 的 Google Nexus 7 上运行时,我在 ListView 项之后立即看到按钮和 TextView 。如果 ListView 是空的,我会在屏幕顶部看到它们。难道我做错了什么??这是我的 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/attachments_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:orientation="vertical">
<ListView
    android:id="@+id/mtg_attachments"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />
<Button
    android:id="@+id/attach_delete"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/delete"
    android:textSize="22sp" />
<TextView
    android:text="@string/attach_warning"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="18sp" />
</LinearLayout>

最佳答案

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/attachments_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1" >
<ListView
    android:id="@+id/mtg_attachments"
    android:layout_width="fill_parent"
    android:layout_height="70dp"
    android:layout_weight="0.9" />
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_weight="0.1"
    android:gravity="bottom" >
    <Button
        android:id="@+id/attach_delete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="delete"
        android:textSize="22sp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="attach_warning"
        android:textSize="18sp" />
</LinearLayout>
</LinearLayout>

关于android - 试图在 Android 中将按钮推到线性布局的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12907190/

相关文章:

android - 删除在开发 Android 中安装新版本应用程序时的共享首选项

android - 当内部类依赖于 R.java 时,Gradle 在 Android Javadocs 中排除 R.java

android - 如何在 Android 的 Spinner View 中添加左侧可绘制对象

android - 以编程方式设置 android 形状颜色

Android 设计支持库 : TabLayout tabs text in single line

android - 与屏幕右侧对齐,Android 有边距

android - 如何设置bottom_margin等于其高度?

android - 就单元测试而言,Android 的 MVP 或 MVVM?

android - LinearLayout问题(同一个XML中的2个LLayout)

android - 布局资源文件中的两个线性布局,但只有一个显示