Pager scrollable tab layout design android development

//in more block

// Create a list of pages
int[] pageId = {
R.layout.page1, R.layout.page3, R.layout.page5

// Define Adapter for ViewPager
private class MyPagerAdapter extends {

// Get total number of pages
public int getCount() {
return pageId.length;

// Get Title of pages
public CharSequence getPageTitle(int position) {
String[] pageTitle = {"Tab-1", "Tab-2", "Tab-3"};
return pageTitle[position];

// Get the Views to be displayed at each position
public Object instantiateItem(View collection, int position) {
// Get View from their Ids
View view = getLayoutInflater().inflate(pageId[position], null);
((, 0);

// Return the View corresponding to position selected
return view;

public void destroyItem(View arg0, int arg1, Object arg2) { (( arg0).removeView((View) arg2);

public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);

//in on activity

// Create a ViewPager, set adapter for it, and set it's current item to position 0 (page1.xml). viewPager1 = new;
viewPager1.setAdapter(new MyPagerAdapter());

// Define a new TabLayout, set it up with the ViewPager, and add it to the AppBarLayout which surrounds the ToolBar. The AppBarLayout thus will contain ToolBar and TabLayout. tabLayout = new;
(( _toolbar.getParent()).addView(tabLayout);
// Add the ViewPager to linear1 of main.xml

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.