javaandroidxmlandroid-recyclerviewrecyclerview-layout

Attach TextView to RecyclerView


I realize the following is incorrect but I suppose you can treat it as pseudocode. I'm wondering, how can I "attach" a whole layout to my RecyclerView so that when I scroll down the layout scrolls out of sight along with it. Presently the TextView above the RecyclerView is fixed on the screen, whereas all the data in my RecyclerView is scrollable. I want the TextView to move out of sight as the user scrolls down the page as well. If you look at Instagram, all the user profile information at the top of your gallery disappears as you scroll down the page. How can I do this? How can I add the TextView programatically?

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Hello!" />

<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="?android:attr/actionBarSize"
    android:padding="@dimen/item_margin"
    android:id="@+id/recycler_view"
    android:clipToPadding="false">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Hello!" />

</android.support.v7.widget.RecyclerView>

Solution

  • I did the same using these two great resources:                                                        

    https://plus.google.com/114432517923423045208/posts/EdkQFx1RqhE

    https://gist.github.com/gabrielemariotti/4c189fb1124df4556058