如何在导航抽屉中创建一个可扩展的listView? [英] how to create an expandable listView inside navigation drawer?

查看:77
本文介绍了如何在导航抽屉中创建一个可扩展的listView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个导航抽屉,例如flipkart或Astro文件管理器应用程序. 如何用可扩展的listView替换listView?

I need to create a navigation drawer like flipkart or Astro file manager app. How can I replace a listView with an expandable listView?

我需要一个这样的导航抽屉:

I need an navigation Drawer like this:

这是我的xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".MainActivity">
<include
    layout="@layout/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />


<!-- This DrawerLayout has two children at the root  -->
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- This LinearLayout represents the contents of the screen  -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <!-- The main content view where fragments are loaded -->
        <FrameLayout
            android:id="@+id/flContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />


    </LinearLayout>
    <!-- The navigation drawer that comes from the left -->
    <!-- Note that `android:layout_gravity` needs to be set to 'start' -->

    <android.support.design.widget.NavigationView
        android:id="@+id/nvView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        app:headerLayout="@layout/nav_header"
        android:choiceMode="singleChoice"
        app:menu="@menu/drawer_view" />

</android.support.v4.widget.DrawerLayout>

推荐答案

您可以创建一个ExpandableListView并将其用作NavigationView. xml结果的示例:

You can create an ExpandableListView and use it as your NavigationView. An example of xml result:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".MainActivity">

<include
    layout="@layout/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<!-- This DrawerLayout has two children at the root  -->
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<!-- This LinearLayout represents the contents of the screen  -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- The main content view where fragments are loaded -->
    <FrameLayout
        android:id="@+id/flContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</LinearLayout>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->

 <ExpandableListView
            android:id="@+id/lvExp"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_gravity="start"/>   

</android.support.v4.widget.DrawerLayout>

您可以找到使用ExpandableListView的示例此处

You can find an example of using an ExpandableListView here

这篇关于如何在导航抽屉中创建一个可扩展的listView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆