android - 抽屉中的可滚动页脚

标签 android xml android-layout

我试图在抽屉中添加页脚。它有效,但它保持固定并且覆盖了一些菜单项。我该怎么做才能将页脚放在列表的末尾(在最后一个元素之后)。它从 xml (activity_main_drawer.xml) 中获取菜单项,并且它有一个标题 (nav_header_main.xml)

抽屉的代码是这样的:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <include
            layout="@layout/app_bar_main"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/side_nav_bar"
            android:id="@+id/content_main"/>
    </LinearLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer">
        <include layout="@layout/nav_footer_main"></include>
    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

页脚代码(nav_footer_main.xml)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="@dimen/nav_footer_height"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    android:background="@drawable/side_nav_bar"

    android:baselineAligned="false"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:scaleType="centerCrop"
        app:srcCompat="@mipmap/copyright"
        tools:ignore="ContentDescription" />

    <TextView
        android:id="@+id/copyright"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/copyright" />
</LinearLayout>

最佳答案

根据@Adreamus 对问题 How to add footer to NavigationView - Android support design library? 的回答

你可以通过 2 个导航 View 来实现,看看这个应用程序 example on Github

此外,我建议您使用 MaterialDrawer Library它会为你节省很多时间

enter image description here

关于android - 抽屉中的可滚动页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46505186/

相关文章:

android - 显示嵌套的 LinearLayout 时出错

android - 方向改变后过渡闪烁

java - Android 中如何将两个不同的列表合并为一个列表

php - 使用 ajax POST 发送的 XML 未在服务器端接收(Laravel 5)

android - 布局旋钮和按钮 View

android - 如何更改底部导航上的非 Activity 颜色?

android - Android-Gradle:与应用程序具有不同targetSDK版本的库

java - 创建 xml 文档并添加或仅在文档存在时添加

java - 为什么仅使用 XML 元素定义 log4j 对象不起作用?

Android 对 flinger 术语的使用?