安卓:如何在布局底部包含另一个布局?

3
我正在尝试将一个布局附加到每个活动的底部,如下所示:
<RelativeLayout 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"
    tools:context=".MainActivity" >

<include
    android:id="@+id/bottom_Menu"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    layout="@layout/bottom_menu" />


</RelativeLayout>

然而,它没有将它放在底部。

----编辑-----

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

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center" >

        <ToggleButton
            android:id="@+id/scheduleToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/SchedueToggle" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center" >

        <ToggleButton
            android:id="@+id/exhibitorsToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/exhibitorsToggle" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center" >

        <ToggleButton
            android:id="@+id/speakersToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/speakersToggle" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center" >

        <ToggleButton
            android:id="@+id/MapsToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/MapsToggle" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center" >

        <ToggleButton
            android:id="@+id/OtherToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/OtherToggle" />

    </LinearLayout>

</LinearLayout>

它放在哪里?bottom_menu.xml是什么样子的? - codeMagic
你为什么同时将它左对齐和右对齐?选择一个或居中。 - VM4
@VM 将其钩到右侧和左侧,使其全宽。 - jcaruso
我认为它不是这样工作的。如果你想让它的宽度全屏,指定layout_width="match_parent"。 - VM4
@codeMagic,我通过将其包装在另一个布局中使其正常工作了... - jcaruso
显示剩余3条评论
1个回答

3
您不需要将其包装在布局中,include需要指定layout_width和layout_height以使其他layout_*字段生效。 从文档中可以得知:

然而,如果您想使用tag覆盖layout属性,则必须同时覆盖android:layout_height和android:layout_width,以使其他layout属性生效。

因此,您的更新布局如下:

<include
    android:id="@+id/bottom_Menu"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    layout="@layout/bottom_menu" />

这个包含的布局在键盘上浮动。有什么解决方法吗? @VM4 - Sid

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接