Fixed Tabs with android.support.v4.view.PagerTabStrip or ViewPagerIndicator

Sebastian Engel picture Sebastian Engel · Dec 2, 2012 · Viewed 7.2k times · Source

In my app I have a Sherlock ActionBar with spinner navigation ("ActionBar.NAVIGATION_MODE_LIST"). In one activity I have two fragments which shall be switchable via tabs. What I did now, was to put the fragment loading into a ViewPager ("android.support.v4.view.ViewPager") together with a "android.support.v4.view.PagerTabStrip" for switching between the fragment tabs.

My problem is now, that these are horizontal scrollable tabs. Same seems to be with Jake Whartons viewpageindicator (viewpagerindicator.com). But what I want is two fixed tabs beside each other. How is that possible with the the support library or with the viewpageindicator?

For wording see http://developer.android.com/design/building-blocks/tabs.html

Answer

CommonsWare picture CommonsWare · Dec 2, 2012

But what I want is two fixed tabs beside each other. How is that possible with the the support library or with the viewpageindicator?

You will have to write your own indicator. Or, you can use action bar tabs in concert with a ViewPager, but that will conflict with your existing action bar navigation and cannot be relied upon to give you tabs in any case.

Since the tabs will only meaningfully scroll if they are too big for the screen, personally I would not worry about this issue.