Adding RecyclerView to Our Layout
In Chapter 3, Screens and UI, we saw how we can add views to our layouts to be inflated by activities, fragments, or custom views. RecyclerView
is just another such view. To add it to our layout, we need to add the following tag to our layout:
<androidx.recyclerview.widget.RecyclerView     android:id="@+id/recycler_view"     android:layout_width="match_parent"     android:layout_height="wrap_content"     tools:listitem="@layout/item_sample" />
You should already be able to recognize the android:id
attribute, as well as the android:layout_width
and android:layout_height
ones.
We can use the optional tools:listitem
attribute to tell Android Studio which layout to inflate as a list item in our preview toolbar. This will give us an idea of how RecyclerView
might look in our app.
Adding a RecyclerView
tag to our layout...