如何整合导航抽屉内扩展列表视图?

问题描述 投票:1回答:2

我创建了一个项目我可扩展列表视图。另外,我在其他主要的项目,我创建了一个导航的抽屉里。一切工作正常,因为它是自己的。不幸的是,我想告诉我的导航抽屉内此扩展列表视图,我不知道从哪里开始。我觉得应该有轻微的增加(已具备适配器和东西),但严重我不知道如何实现抽屉内的布局思路。我搜索关于这个话题,所有的例子和答案并不那么清晰。

能否请你点我正确的方向?

android navigation-drawer expandablelistview
2个回答
0
投票

你可以像下面的ExpandableListView加入NavigationDrawer做到这一点:

您可以使用自定义的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


0
投票

创建自定义布局使用自定义导航视图中(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"/>
© www.soinside.com 2019 - 2024. All rights reserved.