我在 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/