如何将AppBar固定在底部

时间:2016-02-01 14:46:39

标签: android android-layout

我有这个布局:

    <LinearLayout>
    <LinearLayout>
<!--This layout is fixed at the top-->
    </LinearLayout>
    <ScrollView>
    </ScrollView>
    <LinearLayout>
            <android.support.v7.widget.Toolbar
                android:id="@+id/my_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:elevation="4dp"
                android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                xmlns:a
    </LinearLayout>
    </LinearLayout>

我认为这个appbar应该看起来固定在底部,但appbar并不是全部。如何让appbar看到底部?感谢。

2 个答案:

答案 0 :(得分:1)

如果您希望使用工具栏作为页脚,

您需要注意的事项是您使用的ScrollView恰好占用了布局上的所有空间,因此要管理您可以使用layout_weight属性,方法是将其设置为1ScrollView将占用空间的其余部分,这是在容纳toolbar

之后留下的
<?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:background="@android:color/holo_blue_dark"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:layout_weight="1"
        android:background="@android:color/darker_gray">

    </ScrollView>

    <android.support.design.widget.AppBarLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/my_custom_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay">
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

</LinearLayout>
  

输出   enter image description here

答案 1 :(得分:0)

目前,没有直接的方法。根据Google的设计指南,App Bar不应出现在底部。阅读此document

如果您真的想这样做,可以按照article进行操作。它用于在底部对齐ActionBar。但你也可以用它来对齐AppBar。