android - 如何在屏幕底部放置相对布局(或线性布局)。?

标签 android

我在 xml 中有以下内容

我想将第二个线性布局放在屏幕底部。 我该怎么办? 我已经将第二个 Relative 布局的属性设置为 bottom 但仍然没有显示在底部..

**

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent">    
<RelativeLayout android:id="@+id/RelativeLayout01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">   
</RelativeLayout>
<RelativeLayout android:id="@+id/RelativeLayout02" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">   
</RelativeLayout>
<RelativeLayout android:layout_height="wrap_content" 
    android:layout_width="fill_parent"
    android:layout_gravity="bottom">
</RelativeLayout>
</LinearLayout>

** 提前致谢

最佳答案

我也在找这个。我刚刚找到的解决方案是使用属性:

android:layout_alignParentBottom="true"

代替你现有的 android:layout_gravity="bottom"

不幸的是,只有当有一个额外的 RelativeLayout 作为根布局 并将其余布局添加到其中时,这对我的布局才有效。也许情况并非总是如此,但是有了 LinearLayout(即使被告知使用 fill_parent)它只使用所有添加元素所需的高度并将我的页脚放在那些的底部。

我来到这个解决方案,看着这个相关的问题:How do I achieve the following result using RelativeLayout?

在此处编辑,因为答案评论中的格式丢失了: 你是说你不能重写它还是它不起作用?

我也有一个垂直的 LinearLayout 并且我的新 xml 结构看起来(没有布局大小参数等)......像这样:

<RelativeLayout>
    <RelativeLayout 
        android:id="@+id/RelativeLayout01">
    </RelativeLayout>
    <RelativeLayout 
        android:id="@+id/RelativeLayout02" 
        android:layout_below="@+id/RelativeLayout01">   
    </RelativeLayout>
    <RelativeLayout 
        android:layout_below="@+id/RelativeLayout02" 
        android:layout_alignParentBottom="true">
    </RelativeLayout>
</RelativeLayout>

关于android - 如何在屏幕底部放置相对布局(或线性布局)。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3802353/

相关文章:

java - 如何在不每次加载模拟器的情况下在 android 模拟器上运行测试?

android - 申请 child 监护

java - 为什么消息在传递到另一个线程时会丢失其内容?

java - Fragment 中的 RecyclerView 错误

android - 开始一个新的 Activity 按钮按下一个按钮

java - 空对象引用上的 android.content.Context.getPackageName()

android - kotlin 委托(delegate)属性,在 get() 方法中我如何访问该值?

android - 如何向选项卡标签添加填充?

java - robotsium 测试项目在 eclipse 中构建,但不在 ant 中构建

android - 解析推送通知仅适用于模拟器