如何定位导航视图菜单项? [英] How to position menu items in Navigation View?

查看:191
本文介绍了如何定位导航视图菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是从设计支持库与最近发布的导航视图

我要放置登录导航视图的底部,我可怎么办呢?
我的菜单 XML 现在,像这样:

 <?XML版本=1.0编码=UTF-8&GT?;
<菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>    <组机器人:checkableBehavior =单一>
        <项目
            机器人:ID =@ + ID / navigation_sub_item_1
            机器人:图标=@绘制/ ic_action_event
            机器人:标题=@字符串/家/>
        <项目
            机器人:ID =@ + ID / navigation_sub_item_2
            机器人:图标=@绘制/ ic_action_person
            机器人:标题=@字符串/ profile文件/>
        <项目
            机器人:ID =@ + ID / navigation_sub_item_3
            机器人:图标=@绘制/ ic_action_labels
            机器人:标题=@字符串/标签/>
        <项目
            机器人:ID =@ + ID / navigation_sub_item_4
            机器人:图标=@绘制/ ic_action_settings
            机器人:标题=@字符串/ log_in/>
    < /组>&所述; /菜单>

下面是我的布局:

 <?XML版本=1.0编码=UTF-8&GT?;
    <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
        机器人:ID =@ + ID /视图
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:fitsSystemWindows =真
        机器人:背景=@色/ white_1000>        <包括
            机器人:ID =@ + ID /工具栏
            布局=@布局/工具栏/>        < android.support.v4.widget.DrawerLayout
            机器人:ID =@ + ID / drawer_layout
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            机器人:layout_below =@ ID /工具栏>            <的FrameLayout
                机器人:ID =@ + ID / content_frame
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =FILL_PARENT/>            < android.support.design.widget.NavigationView
                机器人:ID =@ + ID / main_drawer
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =match_parent
                机器人:layout_gravity =开始
                应用:headerLayout =@布局/ drawer_header
                应用:菜单=@菜单/ drawer_menu/>    < /android.support.v4.widget.DrawerLayout>< / RelativeLayout的>


解决方案

你想让你的登录项目被固定在导航视图的底部?

您可以做到这一点通过在 NavigationView 筑巢其他视图/布局。 NavigationView扩展的FrameLayout ,这样你就可以将其套在孩子的意见。

我这里张贴在NavigationView页脚更多信息。还看到在该职位其他答案更多的布局选项。

修改

FYI:如果您使用固定页脚的方式,你基本上(在你的榜样例如登录),从菜单中删除页脚项目。这意味着你必须实现点击其他处理自己。

My question is related to recently released Navigation View from Design Support Library.

I want to position Log In at the bottom of the Navigation View, how I can do this? My menu XML right now, look like this :

<?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/navigation_sub_item_1"
            android:icon="@drawable/ic_action_event"
            android:title="@string/home" />
        <item
            android:id="@+id/navigation_sub_item_2"
            android:icon="@drawable/ic_action_person"
            android:title="@string/profile" />
        <item
            android:id="@+id/navigation_sub_item_3"
            android:icon="@drawable/ic_action_labels"
            android:title="@string/tags" />
        <item
            android:id="@+id/navigation_sub_item_4"
            android:icon="@drawable/ic_action_settings"
            android:title="@string/log_in" />
    </group>

</menu>

Here is my layout :

     <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:background="@color/white_1000">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />

        <android.support.v4.widget.DrawerLayout
            android:id="@+id/drawer_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/toolbar">

            <FrameLayout
                android:id="@+id/content_frame"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />

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

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

</RelativeLayout>

解决方案

Do you want your "Log In" item to be fixed at the bottom of the Navigation View?

You can do that by nesting additional views/layouts within NavigationView. NavigationView extends FrameLayout, so you can wrap it around child views.

I posted more information on NavigationView footers here. Also see the other answers in that post for more layout options.

Edit

FYI: If you use the "fixed footer" approach, you are basically removing the footer item (e.g. "Log In" in your example) from the menu. That means you have to implement click and other handlers yourself.

这篇关于如何定位导航视图菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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