2015-10-20 54 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