Adding fixed / static header to nav DrawerLayout

Like many applications, I use the code DrawerLayout

like this:

<android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_layout"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF"
        tools:context=".MainActivity">
    <!-- The main content view -->
    <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    <!-- The navigation drawer -->



    <ListView
            android:id="@+id/left_drawer"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="right"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="#FFFFFF" />

</android.support.v4.widget.DrawerLayout>

      

I have the user info above ListView

, so I am using addHeaderView()

. However, this is a scroll with a list. I would like the list to look like it scrolls below it and the title stays fixed at the top.

Is it possible? I tried to wrap it ListView

inside LinearLayout

with header code inside this layout. This completely broke the application. Are there other ways? I've actually seen Google do this in at least one of their apps (youtube).

+3


source to share


1 answer


Traversing your list in some kind of layout is the way to go. Maybe you missed something. Try the following:



<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    tools:context=".MainActivity">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <!-- The navigation drawer -->


    <LinearLayout
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_gravity="right">

        <!--SOME HEADER-->
        <View
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <ListView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="#FFFFFF" />
    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

      

0


source







All Articles