2

I am trying to get my scrollable tab to work (a scrolling tab like the menu in Google Play). I am using android.support.v4.app.FragmentTabHost as the tab host and android.support.v4.app.Fragment as fragments. Everything works except that the tab host is not scrollable (I am using a HorizontalScrollView for the scrolling function). If I change the tabhost to the standard android.widget.TabHost and the activity to TabActivity, then it works. So I assume there is something with the FragmentTabHost that does the ScrollView not working.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

        <HorizontalScrollView android:layout_width="fill_parent"
                              android:layout_height="wrap_content"
                              android:fillViewport="true"
                              android:scrollbars="horizontal">
            <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:orientation="horizontal" />
        </HorizontalScrollView>

            <FrameLayout android:id="@android:id/tabcontent"
                         android:layout_width="fill_parent"
                         android:layout_height="fill_parent" >
        </FrameLayout>
    </LinearLayout>

</android.support.v4.app.FragmentTabHost>

And here is some code of the FragmentTabHost:

public class MyTabActivity extends FragmentActivity {

private FragmentTabHost mTabHost;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.news);

    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);



    mTabHost.addTab(
            mTabHost.newTabSpec("tab1").setIndicator("Tab 1",
                    getResources().getDrawable(android.R.drawable.star_on)),
            FragmentTab.class, null);
    mTabHost.addTab(
            mTabHost.newTabSpec("tab2").setIndicator("Tab 2",
                    getResources().getDrawable(android.R.drawable.star_on)),
            FragmentTab.class, null);
    mTabHost.addTab(
            mTabHost.newTabSpec("tab3").setIndicator("Tab 3",
                    getResources().getDrawable(android.R.drawable.star_on)),
            FragmentTab.class, null);
    ......
    ......

If I add more tabs, the tabs just get smaller to fit the screen. The scroll never appears, but I want it scrollable!

What is wrong?

Rox
  • 2,647
  • 15
  • 50
  • 85
  • What you've reference to is a `ViewPager` with a `PagerTitleStrip` and not a `FragmentTabHost`. – user Jul 06 '13 at 16:30
  • Isn´t a `ViewPager` for sliding the whole screen? Or is it possible to slide a part of the screen with a `ViewPager`? – Rox Jul 06 '13 at 17:28
  • You can use a ViewPager to scroll the whole content view or some part of it. http://developer.android.com/training/animation/screen-slide.html – user Jul 06 '13 at 17:41

1 Answers1

0

Using Viewpager is a great idea...However...if you want to stay with this implementation, Consider this XML layout.

 <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="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"/>
        </HorizontalScrollView>
Vishal Kumar
  • 4,419
  • 1
  • 25
  • 31