2015-10-20 136 views
0

我正在研究一个应用程序,我想将导航抽屉添加到包含标题(图像,全名和电子邮件)以及用户在应用程序周围进行导航的ExpandableListView。制作具有ExpandableListView的导航抽屉

到目前为止,我已经使用导航系统创建了ExpandableListView,但我没有设法为导航抽屉制作标题。

我试着制作一个<include/>标签来实现drawer_layout.xml中的头文件,但无济于事。

这是我希望它看起来(忽略ExpandableListView条目;只是一个例子):http://imgur.com/xlsXvd7

这里是我的布局文件:

drawer_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- Activity Content--> 
    <FrameLayout 
     android:id="@+id/activity_frame" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent"> 
    </FrameLayout> 

    <!-- Navigation Drawer Items --> 
    <ExpandableListView 
     android:id="@+id/left_drawer" 
     android:layout_height="match_parent" 
     android:layout_width="240dp" 
     android:layout_gravity="start" 
     android:choiceMode="singleChoice" 
     android:groupIndicator="@android:color/transparent" 
     android:divider="@android:color/transparent" 
     android:background="#444444"/> 

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

drawer_header.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:background="#444444"> 
     <TextView 
      android:id="@+id/name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="16dp" 
      android:textColor="#ffffff" 
      android:text="Example Example" 
      android:textSize="14sp" 
      android:textStyle="bold" 
      android:layout_centerVertical="true" 
      android:layout_alignStart="@+id/email" /> 

     <TextView 
      android:id="@+id/email" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#ffffff" 
      android:layout_marginLeft="16dp" 
      android:text="[email protected]" 
      android:textSize="14sp" 
      android:textStyle="normal" 
      android:layout_alignBottom="@+id/circleView" 
      android:layout_toEndOf="@+id/circleView" /> 

    <de.hdodenhof.circleimageview.CircleImageView 
     android:layout_width="60dip" 
     android:layout_height="60dip" 
     android:src="@drawable/ic_face_white_48dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="20dp" 
     android:id="@+id/circleView" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentStart="true" /> 
</RelativeLayout> 

我也在使用自定义的ExpandableListAdapter(如果需要,会发布代码)。

任何帮助将不胜感激。

谢谢你的时间。

+2

你可以用的' “LinearLayout”中的ExpandableListView'并将其他布局添加到'LinearLayout' –

回答

2

您需要在其他视图中包装您的ExpandableListView

的原因是DrawerLayout可以有两个孩子看,一个用于NavigationDrawer等它充当Container View,我张贴你的XML文件添加看看是否有帮助

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- Activity Content--> 
    <FrameLayout 
     android:id="@+id/activity_frame" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent"> 
    </FrameLayout> 

    <!-- Navigation Drawer Items --> 
    <LinearLayout 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:layout_gravity="start" 
     android:layout_width="240dp"> 

     <include 
      layout="@layout/drawer_header" /> 

     <ExpandableListView 
      android:id="@+id/left_drawer" 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" 
      android:layout_gravity="start" 
      android:choiceMode="singleChoice" 
      android:groupIndicator="@android:color/transparent" 
      android:divider="@android:color/transparent" 
      android:background="#444444"/> 

     </LinearLayout> 

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

谢谢你的答案。如果我将所有内容放入LinearLayout中,我将传递给boolean的哪个参数为drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); ?目前它需要在ExpandableListView中。 – UltraAlkaline

+0

给''LinearLayout''''',然后在java中传递'LinearLayout' –

+0

非常感谢。你为我节省了大量的时间。干杯。 – UltraAlkaline