Android 将包含的布局保留在父布局的底部
我有一个LinearLayout,它保存在一个单独的文件中,并与Android 将包含的布局保留在父布局的底部,android,android-layout,android-linearlayout,android-relativelayout,Android,Android Layout,Android Linearlayout,Android Relativelayout,我有一个LinearLayout,它保存在一个单独的文件中,并与Include一起使用。 问题是我希望这个布局在屏幕的底部。在我的第一个布局中使用RelativeLayout很好。但是在第二个布局中,我使用了LinearLayout,它似乎在android:layout\u alignParentBottom=“true”中不起作用。我如何解决这个问题? 这是我的代码: 包含的布局: ` . . . . ` 在第一个布局中,我有相对布局,在第二个布局中,我有线性布局。如何更改包含的零件,
Include
一起使用。
问题是我希望这个布局在屏幕的底部。在我的第一个布局中使用RelativeLayout很好。但是在第二个布局中,我使用了LinearLayout,它似乎在android:layout\u alignParentBottom=“true”中不起作用。我如何解决这个问题?这是我的代码:
包含的布局:
`
.
.
.
.
`
在第一个布局中,我有相对布局,在第二个布局中,我有线性布局。如何更改包含的零件,使其在RelativeLayout和LinearLayout中均位于底部?无论何时,如果要将此布局包含在父布局中,只需指定其应放置的位置:
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
layout="@layout/yourLayout" />
编辑以下Piyush Gupta注释:如果父布局将成为线性布局,只需替换alignParentBottom即可:
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
layout="@layout/yourLayout" />
为了解决您的困惑,我给您提供了添加页脚的示例代码 页脚布局:Footer\u layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Footer Layout" />
</LinearLayout>
只是简单的文本视图显示为页脚
主布局:activity_Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
layout="@layout/footer_layout" />
</LinearLayout>
输出:
还有任何疑问请告诉我。
看起来android:layout\u alignParentBottom=“true”不起作用。不,没有。它只适用于相对年轻的父级。对于LinearLayout
使用android:layout\u gravity=“bottom”
右侧,这是我的问题。我如何为线性布局修复它?你读过我的评论吗?@piyusgupta是正确的!您是否使用了includeOP希望包含在线性布局中
。适用于RelativeLayout
。尝试一下,但不起作用:/让我在里面多做点。我会使用你的想法,如果我解决了,我会接受你的答案:)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
layout="@layout/footer_layout" />
</LinearLayout>