Scrollable Tabs

813 views
Skip to first unread message

Sanjeev Ramakumar

unread,
Mar 19, 2012, 4:54:47 PM3/19/12
to actionba...@googlegroups.com
I have implemented navigation tabs as part of the action bar, and used ViewPager in order to get a nice swiping effect across the tabs. This works perfectly fine if there are 3 or fewer tabs. When I add a 4th tab, the text in the last tab is cut off, as it seems ABS is dividing the width between the tabs. Is there a way to get a scrolling effect in the tabs as well, so that the width remains the same but the tabs also scroll when the user swipes through the tabs. I tried this on Android 4.0 (minus ABS) using this blog for reference ( http://www.techrepublic.com/blog/app-builder/combining-the-android-viewpager-widget-and-the-actionbar-fragment-tabs/884) and it does scroll the tabs.

Sanjeev Ramakumar

unread,
Mar 20, 2012, 2:14:36 PM3/20/12
to actionba...@googlegroups.com
Any idea on this? Just want to see if it's a known issue with ABS. If so, I can use HorizontalScrollView instead for the tabs.

brandall

unread,
Apr 3, 2012, 5:41:24 PM4/3/12
to actionba...@googlegroups.com
I was wondering about this too - The tabs become squashed rather than scrollable for me. I've searched all over for the answer, but can't find one....

Frank Harper

unread,
Apr 4, 2012, 2:28:24 AM4/4/12
to actionba...@googlegroups.com
If you don't have enough space for all your tabs, I think you should look into using ViewPager (from support library) and ViewPagerIndicator (from Jake of ABS fame).

brandall

unread,
Apr 4, 2012, 5:59:28 AM4/4/12
to actionba...@googlegroups.com
Hi Frank, just to confirm, scrollable tabs aren't available in the latest version then? I'm not missing something obvious? I was using the ViewPager, but it was playing havoc with my code, restarting activities that weren't even in view etc - I was hoping switching back to tabs would be less of a headache for me... 

brandall

unread,
Apr 6, 2012, 8:44:23 AM4/6/12
to ActionBarSherlock
The solution turned out to be very simple for me:

<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >

<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
</HorizontalScrollView>

I wrapped the TabWidget in HorizontalScrollView (in fragment_tabs.xml)
and now it works. I'm sure I need to make a few further adjustments,
but now my multiple tabs are well spaced and scrollable...
Reply all
Reply to author
Forward
0 new messages