0

I'm trying to do the same thing @lnamdar asked in this question (Drawer layout with fixed menu item). I'm trying to get a better explanation on their solution.

I'm trying this:

<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"
android:background="@android:color/black">

<!-- The main content view -->
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/transparent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/black"
        android:text="This is the footer text"/>

</RelativeLayout>

<!-- The navigation drawer -->
<ListView
    android:id="@+id/left_drawer"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:background="@android:color/black"/>

But this is causing the list view not to show and when I toggle open/close the only thing that I see is the footer. I tried to put both the listView and the footer textView inside the RelativeLayout but then it crashes with a ClassCastException on the Layout Params used on the Drawer Layout class.

Thanks for your help!

4

1 回答 1

0

他们对 RelativeLayout 的尝试给出了意想不到的结果,因为它不在内容框架内。解释非常简单,因为 RelativeLayout 是ListView保存菜单项的父级,我们将重力移动到它,而不是使用ListView相同的重力。这是我所做的:

<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" />

    <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>

不要忘记运行 HierarchyViewer 以摆脱不必要的 ViewGroup。

于 2013-11-30T04:31:25.627 回答