天天看點

android navigationview menu布局,NavigationView中的菜單自定義布局?

我需要建立一個導航抽屜,第一個菜單包含5個預定義項目(這些将永遠不會改變)。在第一個菜單下面,我想要第二個菜單,其中包含具有自定義布局的可變數量的項目。NavigationView中的菜單自定義布局?

解釋的圖像:

android navigationview menu布局,NavigationView中的菜單自定義布局?

這裡是我的主要活動看起來像現在:

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

android:id="@+id/main_content"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/appbar"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

app:layout_scrollFlags="scroll|enterAlways"

app:popupTheme="@style/AppTheme.PopupOverlay" />

android:id="@+id/tablayout"

android:layout_width="match_parent"

android:layout_height="48dp" />

android:id="@+id/container"

android:layout_width="match_parent"

android:layout_height="match_parent"

app:layout_behavior="@string/appbar_scrolling_view_behavior" />

android:id="@+id/nav_view"

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:layout_gravity="start"

android:fitsSystemWindows="true">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

layout="@layout/nav_header_drawer" />

android:id="@+id/drawer_listview"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_gravity="left"

android:choiceMode="singleChoice" />

其中一期工程,但現在我不能使用app:menu="@menu/navigation_drawer_items"屬性NavigationView,因為ListView項目與菜單項重疊。

這是菜單XML:

android:id="@+id/nav_share"

android:icon="@drawable/ic_menu_share"

android:title="Share" />

android:id="@+id/nav_send"

android:icon="@drawable/ic_menu_send"

android:title="Send" />

有沒有辦法,我可以加載菜單XML 和顯示下面的菜單自定義布局的方法嗎?有沒有不同的想要做到這一點?