抽屉布局固定菜单项 [英] Drawer layout with fixed menu item
问题描述
我们已经实施 DrawerLayout
这是工作的罚款。然而,我们想有是在屏幕的底部,并显示在抽屉里只有打开时,一个固定的菜单选项(注销)。页脚是不是一种选择,因为它会一直显示在菜单列表的最后一项,而我们总是希望它在菜单的底部。我们之所以能有与在 onDrawerOpened()
,但平局的开关闭该按钮抽屉成为最顶层可见的按钮相对布局。请求焦点无助的抽屉打开动画甚至重点reqest后会发生
在任何情况下,我们正在寻找:
- 无论是如何在底部随时添加这个菜单项
或 -
请在菜单显示抽屉打开后。
公共无效onDrawerOpened(查看drawerView){ 。getActionBar()的setTitle(的getTitle());
invalidateOptionsMenu(); //创建调用上prepareOptionsMenu();
logoutButton.setVisibility(View.VISIBLE);
logoutButton.setFocusable(真);
logoutButton.requestFocus();
logoutButton.requestLayout();
//drawerLayout.addView(logoutView,0);
}
您尝试与RelativeLayout的是给意外的结果,因为它不是内容的框架内。下面是我所做的:
< android.support.v4.widget.DrawerLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / drawer_layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
<的FrameLayout
机器人:ID =@ + ID / content_frame
机器人:layout_width =match_parent
机器人:layout_height =match_parent/>
< RelativeLayout的
机器人:ID =@ + ID / relative_layout
机器人:layout_width =240dp
机器人:layout_height =match_parent
机器人:layout_gravity =开始> < ListView控件
机器人:ID =@ + ID / left_drawer
机器人:layout_width =240dp
机器人:layout_height =match_parent
机器人:背景=#111
机器人:choiceMode =singleChoice
机器人:分=@机器人:彩色/透明
机器人:dividerHeight =0dp/> < RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentBottom =真正的> <的FrameLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:背景=机器人:ATTR / activatedBackgroundIndicator
机器人:layout_alignParentBottom =真
机器人:ID =@ + ID /持有者> <的TextView 机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=机器人:ATTR / activatedBackgroundIndicator
机器人:重力=center_vertical
机器人:ID =@ + ID / logout_item
安卓了minHeight =机器人:ATTR /列表preferredItemHeightSmall
机器人:paddingLeft =16DP
机器人:paddingRight =16DP
机器人:文字=@字符串/注销
机器人:textAppearance =机器人:ATTR / textAppearanceListItemSmall
机器人:文字颜色=#FFF/> < /&的FrameLayout GT;
< / RelativeLayout的>< / RelativeLayout的>< /android.support.v4.widget.DrawerLayout>
不要忘了运行HierarchyViewer摆脱不必要的的ViewGroup
。
We have implemented DrawerLayout
which is working fine. However we would like a fixed menu option(logout) that has to be at the bottom of the screen and show up when the drawer opens only. The footer was not an option as it would always shows up as last item in the menu list rather we always want it at the bottom of the menu. We have been able to have a relative layout with the button that is made visible in the onDrawerOpened()
but opening of the draw closes that button as the drawer becomes the topmost layer. Requesting focus does not help as the drawer open animation happens even after focus reqest
In any case, we are looking for:
- Either how to add this menu item always at the bottom or
Make the menu show up after the drawer opens.
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); }
You attempt with the RelativeLayout was giving unexpected result since it wasnt inside the content frame. Here is what I did:
<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>
Don't forget to run HierarchyViewer to get rid of unnecessary ViewGroup
.
这篇关于抽屉布局固定菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!