Skip to content

Instantly share code, notes, and snippets.

@polson
Last active July 11, 2019 21:04
Show Gist options
  • Save polson/a15336b398f8490a085ed5f698f72aa3 to your computer and use it in GitHub Desktop.
Save polson/a15336b398f8490a085ed5f698f72aa3 to your computer and use it in GitHub Desktop.
Example of how to add a header to a RecyclerView in XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Replace this ImageView with your header view -->
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_scrollFlags="scroll" />
</android.support.design.widget.AppBarLayout>
<!-- This can be any scrolling view -->
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment