Android using LayoutManagers with RecyclerView

LayoutManager behaviour in Android by using  Recyclerview.The RecyclerView provides built in LayoutManagers and implement vertical scrolling list, horizontal scrolling list , a uniform grid, staggered grid collections.

RecyclerView : The RecyclerView  is more advanced and flexible version of ListView. We can display large number of data sets and that can be maintained  with  limited number of views.

The LayoutManager : The LayoutManager is used for
1. To positioning the items of RecyclerView.
2. Type of RecyclerView like list or grid.
3. The orientations,the item display in Horizontal or Vertical.
4. To calculate size and position of each item in RecyclerView.

RecyclerView provides bulit-in LayoutManagers.

  1. LinearLayoutManager.
  2. GridLayoutManager.
  3. StraggeredGridLayoutManager.

1.LinearLayoutManager is used to display  items in horizontal and vertical scroll.

//initialize recyclerview
  recyclerView = (RecyclerView) findViewById(;

//fixed size of recyclerview layout

//intialize linear layout manager vertically
  LinearLayoutManager linearVertical = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);

//attach linear layout to recyclerview

//initialize linear layout manager horizontally
  LinearLayoutManager linearHorizontal = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);

//attach linear layout to recyclerview

//initialize adapter
  notificationAdapter = new NotificationAdapter(MainActivity.this,recyclerView,dat);

//attach adapter to recyclerview


2.GridLayoutManager is used to display items in a grid.

//here the second parameter is for number of rows.
//third parameter is for horizontal scroll.
//fourth paramter is boolean,when it set to false,layout from start to end
  GridLayoutManager gridHorizontal = new GridLayoutManager(this,2,GridLayoutManager.HORIZONTAL,false);

//attach layout manger to recyclerview

 //for vertical scroll
  //second parameter is for number of columns  
  GridLayoutManager gridVertical = new GridLayoutManager(this,3,GridLayoutManager.VERTICAL,false);



3.StaggeredGridLayoutManager is used to display items in staggered grid.

//here first param represents number of columns
//second param represents vertical scroll
  StaggeredGridLayoutManager staggeredGridVertical=new     

Conclusion: for complete code refer,


Leave a Reply

Your email address will not be published. Required fields are marked *