Android 带固定菜单项的抽屉布局
我们已经实现了Android 带固定菜单项的抽屉布局,android,menu,screen,fixed,slidingdrawer,Android,Menu,Screen,Fixed,Slidingdrawer,我们已经实现了DrawerLayout,运行良好。然而,我们希望一个固定的菜单选项(注销),必须在屏幕底部,并显示时,抽屉只打开。页脚不是一个选项,因为它总是显示为菜单列表中的最后一项,而我们总是希望它位于菜单的底部。我们已经能够在onDrawerOpened()中看到按钮的相对布局,但是当抽屉成为最顶层时,打开绘图关闭按钮。请求焦点没有帮助,因为抽屉打开动画即使在焦点重新测试之后也会发生 无论如何,我们正在寻找: 如何始终在底部添加此菜单项 或 使菜单在抽屉打开后显示 public v
DrawerLayout
,运行良好。然而,我们希望一个固定的菜单选项(注销),必须在屏幕底部,并显示时,抽屉只打开。页脚不是一个选项,因为它总是显示为菜单列表中的最后一项,而我们总是希望它位于菜单的底部。我们已经能够在onDrawerOpened()
中看到按钮的相对布局,但是当抽屉成为最顶层时,打开绘图关闭按钮。请求焦点没有帮助,因为抽屉打开动画即使在焦点重新测试之后也会发生
无论如何,我们正在寻找:
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(getTitle());
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu();
logoutButton.setVisibility(View.VISIBLE);
logoutButton.setFocusable(true);
logoutButton.requestFocus();
logoutButton.requestLayout();
//drawerLayout.addView(logoutView, 0);
}
您尝试使用RelativeLayout时产生了意外的结果,因为它不在内容框架内。以下是我所做的:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/relative_layout"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start" >
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator"
android:layout_alignParentBottom="true"
android:id="@+id/holder" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator"
android:gravity="center_vertical"
android:id="@+id/logout_item"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/logout"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#fff" />
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
不要忘了运行HierarchyViewer以消除不必要的
视图组
这是一个简单的问题,只需将布局_gravity=“start”移动到抽屉布局内部的相对布局即可。