Kamalakannan J
Kamalakannan J

Reputation: 2998

Fixed tabs with ViewPager Android

I'm using ViewPager in my Android application, but I'm more worried, that the tabs are swipeable. I want tabs like Google playstore, it shows 3 or 4 tabs by default, and then tab slides only after 3rd tab.

How can I achieve that kind of Tabs with Viewpager ?

Upvotes: 1

Views: 2393

Answers (2)

savepopulation
savepopulation

Reputation: 11921

You can check swipe tabs basic project from here: http://developer.android.com/samples/SlidingTabsBasic/project.html

And download sample source code from here: http://developer.android.com/downloads/samples/SlidingTabsBasic.zip

Also this is a useful library which I use in my projects: https://github.com/astuetz/PagerSlidingTabStrip

You should set your pager's tab strip's view attribute

pstsShouldExpand=true

I hope this'll help you.

Upvotes: 3

Joe Maher
Joe Maher

Reputation: 5460

I couldn't for the life of me work out how to do this without an external library, i ended up going with https://github.com/astuetz/PagerSlidingTabStrip.

Quite easy to implement

    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new yourViewPagerAdapter()));

    PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);

    tabs.setViewPager(viewPager);
    tabs.setOnPageChangeListener(this);

Upvotes: 1

Related Questions