Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Scrollable tabs

Tags:

android

tabs

I'm currently working on my first android application. I am using a tabbed layout for my application. I followed the tutorial for this on the dev guide and ran into a problem. The tutorial only used three tabs, but I have a need for more. As such, the tabs resize and bunch up. I was hoping someone could tell me how I can make them scroll, like in dolphin browser when using multiple tabs. Thanks!

~aaron

like image 554
ariets Avatar asked Jun 19 '10 15:06

ariets


2 Answers

Using what Yoel said, just add: android:fillViewport="true and android:scrollbars="none"

to HorizontalScrollView like this:

    <HorizontalScrollView 
       android:id="@+id/horizontalScrollView1" 
       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" />

    </HorizontalScrollView>
like image 69
Gonan Avatar answered Oct 16 '22 22:10

Gonan


I would recommend to wrap the TabWidget with HotizontalScrollView instead. this way you can still use the tabs as they are.

    <HorizontalScrollView 
        android:id="@+id/horizontalScrollView1" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        >

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

It is important to note that if you are using less tabs, this will cause the tab's not to fill the whole width of the screen. I am currently looking for a solution for this issue.

like image 36
Yoel Gluschnaider Avatar answered Oct 16 '22 21:10

Yoel Gluschnaider