Drawer layout with fixed menu item

落花浮王杯 提交于 2019-12-08 00:10:40

问题


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:

  1. Either how to add this menu item always at the bottom or
  2. 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);
        }
    

回答1:


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.



来源:https://stackoverflow.com/questions/17331761/drawer-layout-with-fixed-menu-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!