【发布时间】:2017-08-29 19:55:31
【问题描述】:
我有一个使用抽屉布局和适配器制作的导航抽屉。我想在侧面菜单的底部添加一个注销按钮。我经历了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);
}
如何在菜单底部添加按钮?
【问题讨论】:
-
创建自定义布局并将布局扩展至您的抽屉
-
我相信每一行的布局都不会?不确定
-
@Harshita 检查此链接stackoverflow.com/questions/21796209/…
-
将按钮添加为来自 java 文件的列表视图的页脚视图。
-
正如 Guptsa 所说,创建一个 ArrayAdapter 来扩展您的布局并验证当前项目是否是最后一个项目并扩展按钮。