gpt4 book ai didi

android - 具有固定菜单项的抽屉布局

转载 作者:行者123 更新时间:2023-11-29 01:52:06 28 4
gpt4 key购买 nike

我们已经实现了 DrawerLayout,它运行良好。但是,我们想要一个固定的菜单选项(注销),它必须位于屏幕底部,并且仅在抽屉打开时显示。页脚不是一个选项,因为它总是显示为菜单列表中的最后一项,而我们总是希望它位于菜单底部。我们已经能够使用在 onDrawerOpened() 中可见的按钮进行相对布局,但是当抽屉成为最顶层时,打开抽屉会关闭该按钮。请求焦点无济于事,因为即使在焦点请求之后抽屉打开动画也会发生

无论如何,我们正在寻找:

  1. 如何将此菜单项始终添加到底部或
  2. 在抽屉打开后显示菜单。

        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 以摆脱不必要的 ViewGroup

关于android - 具有固定菜单项的抽屉布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17331761/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com