1

I have a fragment which includes a Textview, and a RecyclerView (list)

My problem is when scrolling the RecyclerView, the textview above it stays on top and doesn't get scrolled.

How do I make the textview to be non-sticky and scrollable like in a ScrollView?

My layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.easyuni.courserecommender.ResultsCareerTabFragment">

    <TextView
        android:id="@+id/tv_results_rec_careers_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center"
        android:layout_marginTop="24dp"
        android:text="@string/results_rec_careers_title"
        android:textSize="24sp"
        android:textStyle="bold" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_careers"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_results_rec_careers_title"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"></android.support.v7.widget.RecyclerView>

</RelativeLayout> 

Screenshots:

Normal look: enter image description here

When scrolling down in RecyclerView: enter image description here

Thanks.

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
Tim
  • 63
  • 1
  • 6

2 Answers2

1

You will need to add your textview as an item that feeds your adapter for your recyclerview. You can use the following code to distinguish between the view that you want to display in your recyclerview:

public int getItemViewType (int position)

Please have a look at this thread:

How to create RecyclerView with multiple view type?

Community
  • 1
  • 1
Simon
  • 19,658
  • 27
  • 149
  • 217
0

You can fix it with this:

Message message = messageList.get(position);

viewHolder.setIsRecyclable(false);

you can lean on this link:

http://www.homebrewandtechnology.com/blog/recyclevewadaptershowwrongdatawhenscrolling