In general, you need to add a layout to RecyclerView by defining your own adapter and then adding the header.

But there is another way to do this, which is to use nested scrollViews, such as this code:

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="30dp">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                 />
                 <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                 />
                 <android.support.v7.widget.RecyclerView
                    android:id="@+id/rv_homework"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
        </LinearLayout>
</ScrollView>
Copy the code

But when you do that, RecyclerView pushes the view above it out of the screen, and then you have to slide down to see it, and that’s because RecyclerView takes the focus, and we just need to add this underneath the unique child layout of the ScrollView

android:descendantFocusability="blocksDescendants"
Copy the code
<LinearLayout
    android:descendantFocusability="blocksDendants"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="30dp">
Copy the code

Android: descendantFocusability this attribute is when a focus for the view access, to define the relationship between the viewGroup and its control.

There are three types of values for attributes:

BeforeDescendants: a viewgroup gets focus before its subclass controls afterDescendants: a viewgroup gets focus only when its subclass controls do not need to get focus blocksDescendants: The viewGroup overrides the subclass control to get focus directlyCopy the code