如何添加页脚NavigationView - 支持Android的设计库? [英] How to add footer to NavigationView - Android support design library?

查看:1683
本文介绍了如何添加页脚NavigationView - 支持Android的设计库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置页脚的设置和配置文件项目 NavitationView ?以貌似收件箱通过电子邮件抽屉式导航。该 NavitationView 项都受到菜单资源夸大,但我不知道如何设置底部项目菜单资源,或者我怎么可以设置自定义视图 NavigationView 或底部偏移?我试图把这个< LinearLayout中...> 作为页脚视图,但在小屏幕上页脚提出过的项目,我不能滚动菜单,我已经试过设置页脚填充,以 NavigationView ,但页脚需要填充了。

这是不滚动在小屏幕上:

 < android.support.design.widget.NavigationView
    机器人:ID =@ + ID /抽屉
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =match_parent
    机器人:layout_gravity =开始
    应用程序:headerLayout =@布局/ kuona_drawer_header
    应用程序:菜单=@菜单/抽屉>

    < LinearLayout中...>

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

这个卷轴,但在菜单项页脚的:

 < android.support.design.widget.NavigationView
    机器人:ID =@ + ID /抽屉
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =match_parent
    机器人:layout_gravity =开始
    机器人:paddingBottom会=96dp
    应用程序:headerLayout =@布局/ kuona_drawer_header
    应用程序:菜单=@菜单/抽屉>

    < LinearLayout中...>

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

抽屉菜单 RES /菜单/ drawer.xml 文件:

 < XML版本=1.0编码=UTF-8&GT?;
<菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <组机器人:checkableBehavior =单一>
        <项目
            机器人:ID =@ + ID / action_current_list
            机器人:检查=真
            机器人:图标=@可绘制/ ic_current_list
            机器人:标题=@字符串/ current_list/>
        <项目
            机器人:ID =@ + ID / action_manage_lists
            机器人:图标=@可绘制/ ic_my_lists
            机器人:标题=@字符串/ my_lists/>
        <项目
            机器人:ID =@ + ID / action_search_products
            机器人:图标=@可绘制/ ic_search_black_24dp
            机器人:标题=@字符串/ search_products/>
        <项目
            机器人:ID =@ + ID / action_deals
            机器人:图标=@可绘制/ ic_product_promo
            机器人:标题=@字符串/交易/>
    < /组>
< /菜单>
 

如果你想有一个固定的(非滚动)页脚的导航菜单解决方案

,你需要使用一个单独的布局,就像你张贴。 NavigationView的工作方式类似的FrameLayout,这样你就可以堆叠一个在你的菜单项的其余部分顶部的LinearLayout。合理安排布局的一种方法是使用布局权重给力您的页脚行至底部,这样的:

固定页脚

 < android.support.design.widget.NavigationView
    机器人:ID =@ + ID /抽屉
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =match_parent
    机器人:layout_gravity =开始
    应用程序:headerLayout =@布局/ kuona_drawer_header
    应用程序:菜单=@菜单/抽屉>

    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:方向=垂直>
        <的TextView
            机器人:ID =@ + ID / empty_spacer
            机器人:layout_width =match_parent
            机器人:layout_height =0dp
            机器人:layout_weight =1
            机器人:可点击=假
            机器人:文本=页脚项目1/>
        <的TextView
            机器人:ID =@ + ID / footer_item_1
            机器人:layout_width =match_parent
            机器人:layout_height =40dp
            机器人:文本=页脚项目1/>
        <的TextView
            机器人:ID =@ + ID / footer_item_2
            机器人:layout_width =match_parent
            机器人:layout_height =40dp
            机器人:文本=页脚项目2/>
    < / LinearLayout中>

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

我用TextViews作为一个例子。任何你想为你的页脚行的项目使用。

如果你做你的页脚就是这样,只要确保了间隔的观点是不能点击,这样点击事件将通过菜单项下面。另外,我只注意到有人张贴另一个答案,但使用layout_gravity =底部。这可能会工作,以及(也许甚至比我的建议更清洁)。

另一种选择,就是只使用一个滚动的脚注。

如果你想页脚项目总是与导航视图的其余部分滚动,它使人们更方便。组> 来获得您可以将您的页脚的项目(例如,反馈和退出)根据&LT只需添加到您的菜单资源文件将其嵌套的结束分隔线,像这样的:

RES /菜单/ drawer.xml

 <菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <组机器人:checkableBehavior =单一>
        <项目
            机器人:ID =@ + ID / action_current_list
            机器人:检查=真
            机器人:图标=@可绘制/ ic_current_list
            机器人:标题=@字符串/ current_list/>
        <项目
            机器人:ID =@ + ID / action_manage_lists
            机器人:图标=@可绘制/ ic_my_lists
            机器人:标题=@字符串/ my_lists/>
        <项目
            机器人:ID =@ + ID / action_search_products
            机器人:图标=@可绘制/ ic_search_black_24dp
            机器人:标题=@字符串/ search_products/>
        <项目
            机器人:ID =@ + ID / action_deals
            机器人:图标=@可绘制/ ic_product_promo
            机器人:标题=@字符串/交易/>
    < /组>
    <组机器人:ID =@ + ID / nav_footer
            机器人:checkableBehavior =单一>
        <项目
            机器人:ID =@ + ID / action_feedback
            机器人:图标=@可绘制/ ic_feeback
            机器人:标题=@字符串/反馈/>
        <项目
            机器人:ID =@ + ID / action_sign_out
            机器人:图标=@可绘制/ ic_sign_out
            机器人:标题=@字符串/ SIGN_OUT/>
    < /组>
< /菜单>
 

How can I set footer settings and profile items to NavitationView? to looks like the Inbox by email navigation drawer. The NavitationView items are inflated by menu resource, but I don't know how to set bottom items to a menu resource, or how can I set a custom view to NavigationView or an bottom offset? I have tried putting this <LinearLayout...> as footer view, but on small screens the footer puts over the items and I cant scroll the menu, I have tried to set a footer padding to NavigationView, but the footer takes the padding too.

This is not scrolling on small screens:

<android.support.design.widget.NavigationView
    android:id="@+id/drawer"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/kuona_drawer_header"
    app:menu="@menu/drawer">

    <LinearLayout...>

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

This scrolls, but the footer its over the menu items:

<android.support.design.widget.NavigationView
    android:id="@+id/drawer"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:paddingBottom="96dp"
    app:headerLayout="@layout/kuona_drawer_header"
    app:menu="@menu/drawer">

    <LinearLayout...>

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

Drawer menu res/menu/drawer.xml file:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">
        <item
            android:id="@+id/action_current_list"
            android:checked="true"
            android:icon="@drawable/ic_current_list"
            android:title="@string/current_list" />
        <item
            android:id="@+id/action_manage_lists"
            android:icon="@drawable/ic_my_lists"
            android:title="@string/my_lists" />
        <item
            android:id="@+id/action_search_products"
            android:icon="@drawable/ic_search_black_24dp"
            android:title="@string/search_products" />
        <item
            android:id="@+id/action_deals"
            android:icon="@drawable/ic_product_promo"
            android:title="@string/deals" />
    </group>
</menu>

解决方案

If you want a fixed (non-scrolling) footer in your navigation menu, you need to use a separate layout like you've posted. NavigationView works like FrameLayout, so you can "stack" a LinearLayout on top of the rest of your menu items. One way to arrange your layout is to use layout weights to force your footer rows to the bottom, like this:

Fixed footer

<android.support.design.widget.NavigationView
    android:id="@+id/drawer"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/kuona_drawer_header"
    app:menu="@menu/drawer">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TextView
            android:id="@+id/empty_spacer"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:clickable="false"
            android:text="Footer Item 1"/>
        <TextView
            android:id="@+id/footer_item_1"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="Footer Item 1"/>
        <TextView
            android:id="@+id/footer_item_2"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="Footer Item 2"/>
    </LinearLayout>

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

I used TextViews as an example. Use whatever else you want for your footer row items.

If you do your footer like this, just make sure that the "spacer" view is not clickable, so that click events will pass through to the menu items beneath. Also, I just noticed that someone posted another answer, but using layout_gravity="bottom". That will probably work as well (maybe even cleaner than my suggestion).

The other option, is to just use a scrolling footer.

If you want footer items to always scroll with the rest of the navigation view, it makes it a lot easier. You can just add your footer items (e.g. "Feedback" and "Sign Out") to the end of your menu resource file and nest them under <group> to get a separator line, like this:

res/menu/drawer.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">
        <item
            android:id="@+id/action_current_list"
            android:checked="true"
            android:icon="@drawable/ic_current_list"
            android:title="@string/current_list" />
        <item
            android:id="@+id/action_manage_lists"
            android:icon="@drawable/ic_my_lists"
            android:title="@string/my_lists" />
        <item
            android:id="@+id/action_search_products"
            android:icon="@drawable/ic_search_black_24dp"
            android:title="@string/search_products" />
        <item
            android:id="@+id/action_deals"
            android:icon="@drawable/ic_product_promo"
            android:title="@string/deals" />
    </group>
    <group android:id="@+id/nav_footer"
            android:checkableBehavior="single">
        <item
            android:id="@+id/action_feedback"
            android:icon="@drawable/ic_feeback"
            android:title="@string/feedback" />
        <item
            android:id="@+id/action_sign_out"
            android:icon="@drawable/ic_sign_out"
            android:title="@string/sign_out" />
    </group>
</menu>

这篇关于如何添加页脚NavigationView - 支持Android的设计库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆