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!

Community
  • 1
  • 1
cperes
  • 33
  • 2
  • 6

1 Answers1

0

Their attempt with the RelativeLayout was giving unexpected result since it wasnt inside the content frame. Explanation is pretty straightforward, since the RelativeLayout is parent of the ListView that hold menu items we move the gravity to it, instead using ListView with same gravity. Here is what I did:

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

Don't forget to run HierarchyViewer to get rid of unnecessary ViewGroup.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • Thanks Nikola, meanwhile I had gotten to the same conclusion and was able to do it. Really appreciate the help! – cperes Dec 19 '13 at 13:33