0

I'd like to have a layout where screen real estate is important on smaller screens, but I'd like users to be able to swipe between exactly two tabs. On these smaller screened devices, I don't want to waste an entire row with a scrollable tab widget like this:

scrollable tabs

but fixed tabs offer no indication to users that they can swipe:

fixed tabs

Users will typically need to view both tabs to complete the task. Is there any way presently to embed tabs with support for "swipe to switch tabs" inside the main action bar?

Jeff Axelrod
  • 25,625
  • 29
  • 137
  • 239
  • 1
    You can use ActionBar tabs with swipe gestures and I don't think that you need to tell users that they can swipe. People that use that gesture will probably try and the ones that don't will find a toast distrubing – zapl Sep 14 '12 at 22:38
  • @zapl even if it's a one-time toast, you think it would be annoying? I've noticed the Yelp app uses something like sideways carets that appear momentarily on the side margins of reviews to indicate that you can swipe to skip to the next/previous review. Until I saw that, it never would have occurred to me to try swiping. – Jeff Axelrod Sep 15 '12 at 00:51
  • `Toast` is IMO a rather annoying thing. They either appear too long or too short to be read depending on how aware you are using the app. Maybe okay to give feedback about actions like in the [UI guidelines](http://developer.android.com/guide/topics/ui/notifiers/toasts.html). If you manage to integrate an unobstrusive visual hint that shows you that swiping is possible I'd prefer that. Hints like that don't need to be one time only and in case you miss to see it the first time you still have a chance the next time you use the app. – zapl Sep 15 '12 at 15:47

2 Answers2

0

You can use Tabs with a ViewPager and a FragmentPagerAdapter.

Link them together like so:

 @Override
 public void onPageSelected(int position) {
     getSupportActionBar().setSelectedNavigationItem(position);
 }

 @Override
 public void onTabSelected(Tab tab, FragmentTransaction ft) {
     mViewPager.setCurrentItem(tab.getPosition());
 }

For a more elaborate example check this answer.

Community
  • 1
  • 1
Benito Bertoli
  • 23,530
  • 12
  • 51
  • 61
0

Not only is it possible to support swiping with standard action bar fixed tabs, it's a design guideline:

Use fixed tabs to support quick changes between two or three app views. Fixed tabs should always allow the user to navigate between the views by swiping left or right on the content area.

enter image description here

Scrollable tabs are different than fixed tabs in that the tab bar itself can be scrolled to see more tabs than will fit on the given display:

enter image description here

Jeff Axelrod
  • 25,625
  • 29
  • 137
  • 239