; paras[X - 1].parentNode.insertBefore(ad1, paras[X]); } if (paras.length > X + 4) { var ad1 = document.createElement('div'); ad1.className = 'ad-auto-insert ad-first'; ad1.innerHTML = ` ; paras[X + 3].parentNode.insertBefore(ad2, paras[X + 4]); } if (isMobile && paras.length > X + 8) { var ad1 = document.createElement('div'); ad1.className = 'ad-auto-insert ad-first'; ad1.innerHTML = ` ; paras[X + 7].parentNode.insertBefore(ad3, paras[X + 8]); } });

Advertisement

Showing posts with label GridLayoutManager. Show all posts
Showing posts with label GridLayoutManager. Show all posts

using LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager with RecyclerView


In the Previous Post, We have created a Recycler View with list of items like listview,

Now we will see how simple to make a gridLayout and |StaggerdGrid with Recycler View by simply modifying the code in the method  to show the items in different ways in the UI .

 mRecyclerView.setLayoutManager(glm);




LinearLayoutManager
=================


mRecyclerView = (AutofitRecyclerView) findViewById(R.id.my_recycler_view);

// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);

LinearLayoutManager llm = new LinearLayoutManager(this);

// use a linear layout manager to show items like listview
mRecyclerView.setLayoutManager(llm);

// create an Object for Adapter
mAdapter = new CardViewDataAdapter(myDataset);

// set the adapter object to the Recyclerview
mRecyclerView.setAdapter(mAdapter);


ScreenShot:





















GridLayoutManager 
================

mRecyclerView = (AutofitRecyclerView) findViewById(R.id.my_recycler_view);

// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
// first param is context and second param is spanCount ie.,
GridLayoutManager glm=new GridLayoutManager(this,2);

// use a grid layout manager to show items like gridview
mRecyclerView.setLayoutManager(glm);

// create an Object for Adapter
mAdapter = new CardViewDataAdapter(myDataset);

// set the adapter object to the Recyclerview
mRecyclerView.setAdapter(mAdapter);


Sreenshot:





















StaggeredGridLayoutManager 
========================


mRecyclerView = (AutofitRecyclerView) findViewById(R.id.my_recycler_view);


// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);


// use a staggerd grid layout manager to show items based on the content width and height.
// first param is spanCount and second param is orientation ie., Vertical or Horizontal
StaggeredGridLayoutManager sglm=new StaggeredGridLayoutManager(2,1); // use a linear layout managermRecyclerView.setLayoutManager(sglm); // create an Object for AdaptermAdapter = new CardViewDataAdapter(myDataset); // set the adapter object to the RecyclerviewmRecyclerView.setAdapter(mAdapter);

Sreenshot:



UPTET news