简体   繁体   中英

Android 2.3.3, making the tab list scrollable?

I have this simple layout that i found as an example:

<?xml version="1.0" encoding="utf-8"?>
<TabHost 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"
        android:orientation="vertical" >

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

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_gravity="center" />
        </HorizontalScrollView>

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

</TabHost>

After adding 8 tabs in the code, i can see that they get squeezed together. How can i add scrollable capabilities to the tabs? (just the tabs, not the content)

One app on my phone has this and that is also done without any scrollbars. Basically, to move i just press-down and hold and then drag the tabs to the left to reveal more tabs. How can this be achieved?

Have you tried this?

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

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </TabHost>

</HorizontalScrollView>

Please try this for your TabWidget:

  <HorizontalScrollView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="none"
    android:layout_alignParentBottom="true">
    <TabWidget
      android:id="@android:id/tabs"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_gravity="center"/>
  </HorizontalScrollView>

You could try setting the minimum width of each tab like so:

    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
        tabHost.getTabWidget().getChildAt(i).setMinimumWidth(200);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM