Android : Recyclerview for beginners(Part- 1)

Richa Sharma
Globant
Published in
2 min readNov 22, 2020

--

  • RecyclerView in Android platform is an important component that is present often in many Android apps.
  • RecyclerView uses an adapter to represent the information we want to show as list.
  • It creates only enough components for the visible screen and allows the user to scroll through the list.
  • RecyclerView is a more advanced version of listview and works based on View holder design pattern. Using recyclerview we can show grids as well as a list of items.

As its name suggests recycles Views once they get out of scope (screen) with the help of ViewHolder pattern.In simple words we can say “recycle” the components by keeping them on the screen and simply changing the data by represent.

  • ListView can also have ViewHolders but that’s not available by default forcing us to add more code to improve list performance.
  • Layout Manager : is responsible for measuring and positioning item views within a Recyclerview.
  • By changing the LayoutManager a RecyclerView can be used to implement a standard vertically scrolling list, a uniform grid, staggered grids, horizontally scrolling collections and more.
  • Its main work is to manage the layout for the large data-set provided by adapter. It positions each item views into it’s appropriate position in the RecyclerView. Also, It re-uses the views that are no longer visible to the user.

There are also some commonly used LayoutManagers :

1.) LinearLayoutManager Arranges items in 1 column or 1 row based on orientation. For example, a horizontal LinearLayoutManager will place items from left to right in 1 row.

2.) GridLayoutManager It arranges all the components in a grid of equally sized cells, adding them from the left to right and top to bottom. Only one component can be placed in a cell and each region of the grid will have the same size.

  • Using recyclerview we can show grids as well as a list of items
  • Adapters : Adapters provide a binding from an app-specific data set to views that are displayed within a RecyclerView.

Three things to keep in mind:

1. ) RecyclerView.Adapter - To handle the data collection and bind it to the view

2. ) LayoutManager - Helps in positioning the items

3. ) ItemAnimator - Helps with animating the items for common operations such as Addition or Removal of item

Simple data diagram
  • ItemAnimator : Recyclerview.ItemAnimator will animate ViewGeoup modifications such as add/delete/select that are notified to the adapter.
  • With these points we can understand what recyclerview works internally in my next blog we will understand RecyclerView with example.

Happy Reading :)

--

--