2017-08-29 3 views
0

enter image description here J'ai un tiroir de navigation fait en utilisant la disposition de tiroir et l'adaptateur. Je veux ajouter un bouton de déconnexion au bas du menu latéral. Je suis passé par SO, mais ne pouvais pas résoudre. Le fichier xml principal a une vue de liste dans une disposition de tiroir.Ajouter un bouton au pied de la liste du tiroir de navigation android

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

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="5" 
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1.5"></LinearLayout> 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="2" 
    android:layout_gravity="center" 
    android:orientation="vertical"> 

     <Button 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="@drawable/buttonbackground" 
     android:text="PHOTOS" 
     android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" 
     android:textColor="@color/white" /> 

     <Button 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="10dp" 
     android:background="@drawable/buttonbackground" 
     android:text="VIDEOS" 
     android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" 
     android:textColor="@color/white" /> 

     <Button 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="10dp" 
     android:background="@drawable/buttonbackground" 
     android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" 
     android:text="HISTORY" 
     android:textColor="@color/white" /> 

     </LinearLayout> 
     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1.5"></LinearLayout> 

     </LinearLayout> 

     <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ListView 
     android:id="@+id/navList" 
     android:layout_width="320dp" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/logout" 
     android:layout_gravity="left|start" 
     android:background="#ffeeeeee"></ListView> 

     <Button 
     android:id="@+id/logout" 
     android:layout_width="320dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="LogOut" /> 
     </RelativeLayout> 
     </android.support.v4.widget.DrawerLayout> 
     <android.support.v4.widget.DrawerLayout/> 

Et la liste est en cours de gonflement dans le code Java.

 private void addDrawerItems() { 
    String items[]={"Home","Video","Camera","History","Version"}; 
    mAdapter=new ArrayAdapter<>(this,R.layout.listview_drawer_item_row,items); 
    mDrawerList.setAdapter(mAdapter); 
} 

Comment ajouter un bouton au bas du menu?

+0

créer une disposition personnalisée et gonfler la disposition de votre tiroir –

+0

Je crois que la disposition sera pour chaque rangée non? Pas sûr – Harshita

+0

@Harshita vérifier ce lien https://stackoverflow.com/questions/21796209/how-to-create-a-custom-navigation-drawer-in-android –

Répondre

0

Pouvez-vous essayer cela, son œuvre autour, mais je l'espère que ça va donner une idée de résoudre votre problème

<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="left|start"> 
     <ListView 
      android:id="@+id/navList" 
      android:layout_width="320dp" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/logout" 
      android:layout_gravity="left|start" 
      android:background="#ffeeeeee"></ListView> 

     <Button 
      android:id="@+id/logout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:text="LogOut" /> 
    </RelativeLayout> 
+0

Cela montre le bouton, mais maintenant, il ne me laisse pas glisser le menu. Le menu couvre l'écran tel qu'il est. – Harshita

+0

Pouvez-vous poster une capture d'écran? – Raghavendra

+0

Oui, je vais faire un montage. – Harshita

0

Selon mon expérience et les connaissances que vous devez ajouter votre bouton de fermeture de session comme footerview de votre listview ou définissez-le en bas dans votre vue de navigation. Vous ne pouvez pas placer votre bouton en dehors de votre navigationView. Si vous parvenez à réaliser quelque chose comme ça, vous ne pourrez que faire défiler votre vue de navigation et non votre bouton de déconnexion. Je suppose qu'il ne défilera pas avec votre navigationview. Pour ce faire, créez une disposition personnalisée selon vos besoins et définissez-la comme une vue d'ensemble ou définissez-la en bas de votre navigationView.