0

Je travaille sur une application à laquelle j'aimerais ajouter un tiroir de navigation contenant un en-tête (image, nom complet et email) et un ExpandableListView où l'utilisateur navigue dans l'application. Jusqu'à présent, j'ai créé ExpandableListView avec le système de navigation, mais je n'ai pas réussi à créer l'en-tête du tiroir de navigation.Faire un tiroir de navigation avec un ExpandableListView

J'ai essayé de créer une balise <include/> pour implémenter l'en-tête dans le fichier drawer_layout.xml, mais en vain.

Voilà comment je veux regarder (ignorer les entrées de ExpandableListView, juste un exemple): http://imgur.com/xlsXvd7

Voici mes fichiers de mise en page:

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> 

tiroir_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> 

J'utilise également un ExpandableListAdapter personnalisé (publiera le code si nécessaire).

Toute aide serait grandement appréciée.

Nous vous remercions de votre temps.

+2

vous pouvez envelopper le ' ExpandableListView' dans un 'LinearLayout' et ajouter d'autres dispositions à cette' LinearLayout' –

Répondre

2

Vous devrez envelopper votre ExpandableListView dans n'importe quel autre affichage.

La raison est DrawerLayout peut avoir deux vue enfant, un pour NavigationDrawer et d'autres qui agit comme Container View, je suis annonce vôtre fichier xml avec ajouts voir si elle aide

<?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

Merci pour la réponse. Si je mets tout dans un LinearLayout, quel paramètre dois-je passer à boolean drawerOpen = mDrawerLayout.isDrawerOpen (mDrawerList); ? Actuellement, il prend dans ExpandableListView. – UltraAlkaline

+0

donner 'id' à ce' LinearLayout', puis en java passer que 'LinearLayout' –

+0

Merci beaucoup mec. Tu m'as sauvé une tonne d'heures. À votre santé. – UltraAlkaline