【问题标题】:How to integrate expandable list view inside navigation drawer?如何在导航抽屉内集成可扩展列表视图?
【发布时间】:2019-02-07 08:50:36
【问题描述】:

我为我的可展开列表视图创建了一个项目。此外,在我的另一个主要项目中,我创建了一个导航抽屉。一切正常,因为它是自己的。不幸的是,我想在我的导航抽屉中显示这个可扩展的列表视图,但我不知道从哪里开始。我觉得应该有一些小的添加(已经有适配器和东西)但严重的是我不知道如何实现抽屉内的布局。我搜索了这个主题,所有的例子和答案对我来说都不是很清楚。

你能告诉我正确的方向吗?

【问题讨论】:

  • 我认为使用/不使用导航抽屉实现可扩展列表视图没有任何区别
  • 使可展开的列表视图出现和消失

标签: android navigation-drawer expandablelistview


【解决方案1】:

您可以通过在NavigationDrawer 中添加ExpandableListView 来实现,如下所示:

您可以使用自定义 ListView 创建它。

查看activity_navigation_view.xml下面的代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    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">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true">

        <ExpandableListView
            android:id="@+id/navigationmenu"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginTop="192dp"
            android:background="@android:color/white">
        </ExpandableListView>
    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

并且只需为其创建适配器并像普通的ExpandableListView 一样使用它。

【讨论】:

    【解决方案2】:

    制作自定义布局以使用自定义导航视图,如下所示 (layout_nav_bar.xml):-

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/color_white"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools">
    
        <include
            android:id="@+id/nav_header"
            layout="@layout/nav_header_main"
            />
    
        <ExpandableListView
            android:id="@+id/expandableListView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none"
            android:overScrollMode="never"
            android:background="@android:color/white"
            android:divider="@null"
            android:groupIndicator="@null" />
    
    </LinearLayout>
    

    将此添加到您的 DrawerLayout

    <include
            android:id="@+id/nav_view"
            layout="@layout/layout_nav_bar"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            android:layout_height="match_parent"
            android:layout_width="match_parent"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-20
      • 2015-04-11
      • 1970-01-01
      • 2016-02-07
      • 2019-01-13
      • 2014-05-04
      相关资源
      最近更新 更多