Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 892
Martin Erlic Avatar asked Dec 23 '15 04:12

Martin Erlic


3 Answers

You can try Android-ObservableScrollView.

Refer following link: https://github.com/ksoichiro/Android-ObservableScrollView

like image 127
Rahul Lad Avatar answered Oct 02 '22 02:10

Rahul Lad


I did the same using these two great resources:                                                        

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

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

                     

like image 38
Javad Jafari Avatar answered Oct 02 '22 02:10

Javad Jafari


You can add that TextView as one of the RecyclerView's items using a custom RecyclerAdapter or you could use a ScrollView with LinearLayout as its content, instead of a RecyclerView as it's not advisable to use one inside a ScrollView.

like image 30
Kyle Emmanuel Avatar answered Oct 02 '22 01:10

Kyle Emmanuel