Building List and Grid Layout With RecyclerView in Android using Java

Grid To List RecylerView

What Is Recycler View?

In this post, We build List and Grid With RecyclerView.

In Older way we were use ListView (Verticle & Horizontal) and GridView. But Material Design as google suggested we have to start Using RecyclerView. Advantage of RecyclerView is we can create list and grid by changing it’s LayoutManager Property.

 

RecylerView

 

Let’s understand RecyclerView With Movie List Example then we show movie list in

KeyPoints of RecyclerView

  • RecyclerView Adapter
  • LayoutManager
  • ItemDecoration

 RecyclerView Adapter

RecyclerView Adapter is Similar to BaseAdapter that  Use in ListView Or GridView But RecyclerViewAdapter is more extended Version Of it and more powerfull than BaseAdapter. You can read More Details from RecyclerViewAdapter.

RecyclerView Adapter Sample Given Below

 

LayoutManager

LayoutManager  is responsible for measuring and positioning item views within a RecyclerView   as well as determining the policy for when to recycle item views that are no longer visible to the user. 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. Several stock layout managers are provided for general use.

Type of Layoutmanager

  • LinearLayoutManager
  • GridLayoutManager
  • StaggeredGridLayoutManager

 

LinearLayoutManager

It is sub class of layoutManager class and shows items in a vertical or horizontal scrolling list also support reverse layout.

for verticle

 

GridLayoutManager

shows items in a grid.

 

StaggeredGridLayoutManager

StaggeredGridLayout is a LayoutManager.help of this manager you can set custom width and height to recylerview item

Example

 

Create Model
Movie.java
 

MovieAdapter.java

 

ListActivity.java

for Grid

RESULT

Grid RecylerView Exmaple

 

StaggeredGridLayoutManager
Hope you will enjoy this tutorial Suggestions are well come. fill free and comment for tutorial or prolem with this tutorial

4138total visits,11visits today

Related posts

Leave a Comment