如何在NavigationView中添加其他布局

3
我正在尝试在NavigationView中添加Expandlistview,但是失败了。我能在标题下面添加布局吗? activity_main布局
<android.support.v4.widget.DrawerLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true">  

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

    <ExpandableListView
        android:id="@+id/expanded_menu"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

让我看看你的整个活动或者你设置抽屉的部分。 - Sheychan
https://dev59.com/omEi5IYBdhLWcg3wndVv - Sree
1
你可以采用以下解决方案:将固定宽度应用于标题布局的根元素,并为ExpandableListView设置相同大小的marginTop - Moinkhan
谢谢你的帮助。我也这么认为。@Moinkhan - Telember
1
不要使用NavigationView来获取它。 - Gabriele Mariotti
显示剩余2条评论
2个回答

1

我的解决方案是,如果你使用的是具有特定高度(例如200dp)的标题布局,则在activity_main.xml文件中为可扩展列表视图标记包含210dp的顶部边距。我希望你没有使用菜单来进行导航视图。

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

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

<ExpandableListView
    android:id="@+id/expanded_menu"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginTop="210dp" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

1
你可以在导航抽屉列表中使用ListView,并将包含可展开ListView的页眉视图附加到列表中。我不确定,但你可以检查一下。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接