【问题标题】:How to add other layout within NavigationView如何在 NavigationView 中添加其他布局
【发布时间】:2015-09-27 10:14:26
【问题描述】:

我试图在我的 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>

【问题讨论】:

  • 让我查看您的整个活动或您设置抽屉的部分
  • @Sree 我想添加像金属设计这样的标题
  • 您可以有一个解决方案是,将固定宽度应用于标题布局的根元素,并为您的ExpandableListView 提供相同大小的marginTop
  • 不要使用NavigationView获取

标签: android android-support-library android-design-library navigationview


【解决方案1】:

我的解决方案是 .. 如果您使用具有特定高度的标题布局,例如 200dp .. 然后在 activity_main.xml 中包括 margin top 0f 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>

【讨论】:

    【解决方案2】:

    您可以在导航抽屉列表中使用列表视图并将标题视图附加到包含可扩展列表视图的列表中。我不确定,但你可以检查一下

    【讨论】:

      猜你喜欢
      • 2017-09-23
      • 2011-07-10
      • 1970-01-01
      • 2015-08-24
      • 2017-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多