如何在导航抽屉内创建​​可扩展的listView?

2024-01-05

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

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

这是我的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 结果示例:

<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 的示例here http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在导航抽屉内创建​​可扩展的listView? 的相关文章

随机推荐

  • glmer 与用户定义的链接函数给出错误:(maxstephalfit) PIRLS 步减半未能减少偏差

    在尝试将用户定义的链接函数与随机效应 glmer 结合使用时 我遇到了一个我不知道如何解决的错误 Error maxstephalfit PIRLS step halvings failed to reduce deviance in pw
  • 当输入文本文件更改时重新启动 Spring Boot

    在这里扩展问题 在 Spring Boot 中启动时从文件中读取数据以在控制器中使用 https stackoverflow com questions 43424524 reading data from file at start to
  • Heroku config:push 不更新环境变量

    我已经将一个应用程序部署到 Heroku 并且当前将环境变量存储在 env 文件中 我用了heroku config push将变量推送到heroku 效果很好 现在 我想更新其中之一 我在 env 文件中更改了它 然后运行heroku c
  • 如何使用 sqoop 在 Hive 中创建外部表。需要建议

    使用 sqoop 我可以创建托管表 但不能创建外部表 请让我知道从数据仓库卸载数据并将其加载到 Hive 外部表中的最佳实践是什么 1 仓库中的表是分区的 有些是按日期分区 有些是按状态分区 请将您的想法或做法应用于生产环境 Sqoop 不
  • 使用 Python 旋转 EXIF 中指定的方向的图像,无需 PIL(包括缩略图)

    我有以下场景 我正在将 iPhone 上的图像连同 EXIF 信息一起发送到我的 Python 套接字服务器 我需要根据拍摄图像时的实际方向正确定位图像 我知道 IOS 总是将图像保存为横向左并将实际方向添加为 EXIF 字段 EXIF I
  • Android:是否可以用数字更新 ImageView/ImageButton 以显示新消息的数量?

    在 iOS 中 我们有一个功能 可以通过在图标的右上角显示一个小数字来为用户更新应用程序图标 并添加新的待处理消息 类似地 我想知道我们是否有方法来更新 ImageView ImageButton在android中 这里我不想更新主屏幕上的
  • 如何在拉取/合并请求之前更新(拉取)分支?

    例如 假设我有一个名为develop 我的所有功能都将是从创建的分支develop稍后我需要执行合并请求 在 GitLab 中 在 GitHub 中将是拉取请求 如果我需要在将新分支推入之前更新它origin并执行合并 拉取请求 git p
  • WebDriverError 错误:Chrome 无法启动:异常退出

    我正在尝试在 ubuntu 14 04 虚拟机上运行量角器测试 通过谷歌云 由于某种原因 当我运行 量角器conf js 时 我收到一条错误消息 E 启动器 WebDriverError 未知错误 Chrome 无法启动 异常退出 我按照此
  • iPhone SDK:锁定方向

    我在以前的应用程序中看到过它 忘记应用程序名称 您可以在其中锁定屏幕的当前方向 有没有一种简单的方法可以完成此操作 例如 只需使用按钮即可 只需将 ivar 添加到您的应用程序委托即可通过按锁定按钮进行设置 然后在所有视图控制器中 您只需检
  • 如何在 Mac 上安装 sshpass?

    我想从我的 Mac 自动进行 ssh 登录 它确实有一个简单的解决方案 sshpass p my password ssh m username hostname 但我的问题是在我的 Mac 上安装 sshpass 2022 年更新 不幸的
  • 尝试启动多个线程时索引超出数组范围

    我有这段代码 它给了我一个 索引超出了数组的范围 我不知道为什么会发生这种情况 因为变量i应始终小于数组的长度bla因此不会导致此错误 private void buttonDoSomething Click object sender E
  • 获取我的 WAN IP 地址

    我怎样才能以编程方式获取从互联网上看到的我的网络的IP地址 显然 我的路由器在连接到 ISP 时可以访问该属性 有没有办法使用标准协议从路由器获取此信息 我唯一的选择是要么找到一个返回我的IP地址的WS 非常难做到 要么就去类似的地方Wha
  • Webpack:如何使角度自动检测 jQuery 并将其用作 angular.element 而不是 jqLit​​e?

    我正在使用 Webpack 构建 Angular 1 4 项目 该项目使用了多个 jQuery 插件 这些插件被包装在 Angular 指令中 这些指令内部使用angular element 可能暗示 angular element 是真正
  • 如何从现有的可观察对象中删除扩展器?

    我正在使用 Knockout Validation 插件 并使用扩展器根据需要设置可观察值 myObservable extend required true 添加扩展器后可以将其删除吗 您可以从可观察对象中删除所有与验证相关的属性 这些属
  • 从 NSDictionary 设置时,BOOL 值从 NO 更改为 Yes

    我有这个代码 if args valueForKey showSetupScreen BOOL showSetupScreen args valueForKey showSetupScreen NSLog showSetupScreen Y
  • Azure ARM“代码”:尝试更新 vnet 时“InUseSubnetCannotBeDeleted”

    我有一个相当简单的 ARM 模板 用于创建 vnet 子网和服务端点 当我尝试更改服务端点时 出现错误 代码 InUseSubnetCannotBeDeleted 指出我的一台虚拟机正在使用其中一个子网 但是 我不想删除该子网 我只是想更新
  • Google Apps 脚本附加源代码/安全性

    我正在构建一个 Google Apps 脚本插件 并想知道当我将其发布到 Marketplace 时是否任何人都可以访问底层源代码 我想在代码中存储密码 私钥 并希望确保安装该应用程序的任何人都无法访问它 使用 Google Apps 脚本
  • SQL:SELECT IN 更快且最佳实践?

    如果我使用 2 个查询 第一 查询所需的所有键 ID 第二 select from tab1 where tab1 id in ids list ids 列表可能有数千个 这样做是明智的 最佳的做法还是推荐的做法 作为一般规则 考虑到您对较
  • php7 中删除了 utf8_(en|de) 代码?

    我最近在我的开发服务器上切换到 PHP 7 到目前为止 它运行得很好 自从我更新到PHP 7 0 3 10 deb sury org trusty 1 今天早些时候 utf8 decode and utf8 encode功能不再可用 然而
  • 如何在导航抽屉内创建​​可扩展的listView?

    我需要创建一个导航抽屉 例如 Flipkart 或 Astro 文件管理器应用程序 如何用可扩展的 listView 替换 listView 我需要一个像这样的导航抽屉 这是我的xml