2017-08-29 136 views
0

enter image description here我有一個使用抽屜佈局和適配器製作的導航抽屜。我想在側邊菜單的底部添加一個註銷按鈕。我經歷過,但無法解決。主要的xml文件在抽屜佈局中有一個列表視圖。將按鈕添加到導航抽屜列表的頁腳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/> 

而且這個列表在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); 
} 

如何在菜單底部添加按鈕?

+0

創建一個自定義的佈局和充氣佈局到您的抽屜 –

+0

我相信佈局將是每行不?不知道 – Harshita

+0

@Harshita檢查此鏈接https://stackoverflow.com/questions/21796209/how-to-create-a-custom-navigation-drawer-in-android –

回答

0

你可以試試這個,它周圍的工作,但我希望它會給一些想法來解決您的問題

<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

這顯示按鈕,但現在,它不會讓我滑動菜單。菜單正在覆蓋屏幕。 – Harshita

+0

你可以發佈一個截圖嗎? – Raghavendra

+0

是的,我會做一個編輯。 – Harshita

0

按我的經驗和知識,你需要添加註銷按鈕的footerview您列表視圖或將其設置爲導航視圖的底部。你不能將你的按鈕放置在navigationView之外。如果你設法達到這樣的效果,你將只能滾動你的導航視圖而不是你的註銷按鈕。我認爲它不會與您的navigationView滾動。

爲達到這個目的,根據您的要求進行自定義佈局,並將其設置爲footerview或將其設置在navigationView的底部。