Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在NavigationView中添加页脚按钮_Android_Drawerlayout_Navigationview - Fatal编程技术网

Android 如何在NavigationView中添加页脚按钮

Android 如何在NavigationView中添加页脚按钮,android,drawerlayout,navigationview,Android,Drawerlayout,Navigationview,我跟随帖子在NavigationView底部添加按钮。问题是,只有最后一个NavigationView出现,它占据了整个屏幕高度 这是我的布局: <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id=

我跟随帖子在NavigationView底部添加按钮。问题是,只有最后一个NavigationView出现,它占据了整个屏幕高度

这是我的布局:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Activity here -->

    <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.support.design.widget.NavigationView
            android:id="@+id/navigation_menu_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="top"
            app:menu="@menu/menu_drawer"/>

        <android.support.design.widget.NavigationView
            android:id="@+id/navigation_footer_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:menu="@menu/menu_drawer_footer"/>

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

</android.support.v4.widget.DrawerLayout>


如何解决此问题?

可能需要添加或调整权重和边距,具体取决于您需要顶部和底部的项目数量,但这应该是您需要的:

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_drawer_container"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="10">

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_drawer"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="top"
        android:layout_weight="8"
        app:menu="@menu/drawer" />

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_drawer_bottom"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:layout_gravity="bottom"
        app:menu="@menu/drawer_footer"  />
    </LinearLayout>
</android.support.design.widget.NavigationView>


希望这有帮助:)

最简单的答案是在抽屉布局中添加一个按钮,并在navigationview.xml中将其设置为底部

就这么简单!!!这是代码

<android.support.design.widget.NavigationView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/navigation"
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/navigation_header"
    app:menu="@menu/menu_navigation"
    android:layout_alignParentTop="true">

   <Button
        android:id="@+id/btn_sing_in"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="@string/sign_in"
        android:layout_gravity="bottom"
       />
</android.support.design.widget.NavigationView>

该博客已有几个月的历史,设计支持库在这段时间内进行了一些更新。特别是NavigationView现在在内部使用RecyclerView而不是ListView。有可能这个把戏已经不管用了。使用旧版本的库进行试用,看看是否有什么变化。@Brucelet,你知道另一种解决方案吗?已确认,在23.0.1上此技巧有效,在23.1上没有任何消息?我还需要一个支持NavigationView的粘贴页脚!我用一个简单的例子回答了这个问题,你需要将
app:elevation=0dp
设置为内部导航视图,否则页脚将有一个奇怪的渐变背景。除非有办法消除页脚的滚动效果,否则我坚持在页脚中使用简单的文本视图。不过,这是一个很好的解决方案。button正在隐藏nagivation项,并向上滚动以查看它