2017-08-29 131 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的底部。