我有一个使用抽屉布局和适配器制作的导航抽屉。我想在侧边菜单的底部添加一个注销按钮。我经历过SO,但无法解决。主xml文件在抽屉布局中具有列表视图。
<?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)
你可以尝试一下吗,这是一个解决方法,但我希望它会给你一些解决问题的想法
<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>
答案 1 :(得分:0)
根据我的经验和知识,您需要将注销按钮添加为列表视图的页脚视图,或者在导航视图中将其设置为底部。您不能将按钮放在navigationView之外。如果你设法实现这样的目标,你将只能滚动导航视图而不是你的注销按钮。我假设它不会使用您的navigationView滚动。
要实现此目的,请根据您的要求制作自定义布局,并将其设置为页脚视图或将其设置在navigationView的底部。