【问题标题】:How to position menu items in Navigation View?如何在导航视图中定位菜单项?
【发布时间】:2015-06-03 07:41:47
【问题描述】:

我的问题与最近从Design Support Library 发布的Navigation View 有关。

我想将Log In 定位在Navigation View 的底部,我该怎么做? 我现在的菜单XML,看起来像这样:

<?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>

这是我的布局:

     <?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>

【问题讨论】:

标签: android navigationview


【解决方案1】:

您是否希望将“登录”项固定在导航视图的底部?

您可以通过在NavigationView 中嵌套额外的视图/布局来做到这一点。 NavigationView 扩展了FrameLayout,因此您可以将其包裹在子视图周围。

我在 NavigationView 页脚 here 上发布了更多信息。另请参阅该帖子中的其他答案以获取更多布局选项。

编辑

仅供参考:如果您使用“固定页脚”方法,则基本上是从菜单中删除页脚项目(例如,您的示例中的“登录”)。这意味着您必须自己实现 click 和其他处理程序。

【讨论】:

    【解决方案2】:

    我认为导航菜单就像一个列表视图。所以项目将被放置在一个列表中。

    如果你想让一个项目放在底部,你可以在布局xml的NavigationView标签内自定义

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-29
      • 1970-01-01
      • 2021-07-28
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多