I made a nice android header. The only problem with it is that whenever the user scrolls down, the header follows the scroll. So the header ends up scrolling and remains on the screen.
What I want to happen is for it to stay glued to the very top of the page. Is that possible?
Here is my header:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<!-- android:textColor="@color/white"
-->
<Button android:id="@+id/home_header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/white"
android:text="Home"
android:background="@drawable/ic_menu"
android:textSize="11dp"
/>
<Button android:id="@+id/businesses_header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="11dp"
android:text="Businesses"
android:textColor="@color/white"
android:background="@drawable/ic_menu"
android:layout_toRightOf="@+id/home_header"
/>
<Button android:id="@+id/learn_header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Learn"
android:textColor="@color/white"
android:textSize="11dp"
android:background="@drawable/ic_menu"
android:layout_toRightOf="@+id/businesses_header"
/>
<Button android:id="@+id/questions_header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_weight="1"
android:text="Questions"
android:textSize="11dp"
android:background="@drawable/ic_menu"
android:layout_toRightOf="@+id/learn_header" />
<Button android:id="@+id/extra_help_header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/white"
android:text="Premium"
android:textSize="11dp"
android:background="@drawable/ic_menu"
android:layout_toRightOf="@+id/questions_header"
/>
</LinearLayout>
Thank you
The first thing you should do is change the height in your header to wrap_content:
Then save the header layout in its own layout file (header.xml). Then use include statements whenever you want to use your header.
Here the header stays on top:
Here it scrolls with the content: