簡體   English   中英

帶有固定菜單項的抽屜布局

[英]Drawer layout with fixed menu item

我們已經實現了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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM