How to implement horizontally scrollable tabs?
Asked Answered
S

5

7

I'm trying to implement this application. At the moment I have designed tabs on it and since I have more than 7 tabs it looks too congested. How can I design it so that the tabwidget is scrollable horizontally. I have seen this design on few of the apps at the market but no clue how to implement this in my app.

One app I saw had a horizontal scrollview where it scrolls on its own and when you press the particular image/button it displays some content. It didn't seem to be tabs I guess.

So does anyone have an idea of this?

Selfinsurance answered 14/3, 2012 at 14:27 Comment(0)
V
2

Please check out Jake Wharton's ViewPager app. That is exactly what you need. It is a library project, so you have to include it in your project.

JakeWharton / Android-ViewPagerIndicator

Vitovitoria answered 14/3, 2012 at 14:36 Comment(2)
Hi Calvin thanks for your post It worked for me. I developing an app for a tablet. but the tabs dont take the width of the texts>. Hope you get what i mean it looks all congested Can i define a width for the tab sot hat it holds the complete text in it. eg: if there is a tab saying "User Profile" but it shows only as "User"Selfinsurance
@roses_r just remove the onMeasure(int, int) method from the class TabPageIndicator of the library. It works.Suspense
W
15

TabLayout from Android design library

<android.support.design.widget.TabLayout
    android:id="@+id/categories"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:tabMode="scrollable" />
Waistcoat answered 14/1, 2016 at 13:2 Comment(0)
F
4

This is a pretty good example by using HorizontalScrollView. http://java.dzone.com/articles/scrolling-tabs-android

Fecundate answered 14/3, 2012 at 14:36 Comment(1)
Hi Calvin thanks for your post It worked for me. I developing an app for a tablet. but the tabs dont take the width of the texts>. Hope you get what i mean it looks all congested Can i define a width for the tab sot hat it holds the complete text in it. eg: if there is a tab saying "User Profile" but it shows only as "User"Selfinsurance
V
2

Please check out Jake Wharton's ViewPager app. That is exactly what you need. It is a library project, so you have to include it in your project.

JakeWharton / Android-ViewPagerIndicator

Vitovitoria answered 14/3, 2012 at 14:36 Comment(2)
Hi Calvin thanks for your post It worked for me. I developing an app for a tablet. but the tabs dont take the width of the texts>. Hope you get what i mean it looks all congested Can i define a width for the tab sot hat it holds the complete text in it. eg: if there is a tab saying "User Profile" but it shows only as "User"Selfinsurance
@roses_r just remove the onMeasure(int, int) method from the class TabPageIndicator of the library. It works.Suspense
P
2
<HorizontalScrollView 
    android:id="@+id/vTabs" 
    android:scrollbars="none" 
    android:layout_width="fill_parent" 
    android:layout_alignParentBottom="true"
    android:layout_height="wrap_content">
    <LinearLayout 
        android:orientation="horizontal" 
        android:background="@color/main_color_gray_dk" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content">
        <Button 
            android:enabled="false" 
            android:id="@+id/tab1" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="@string/popular" />
        <View 
            android:id="@id/view1" 
            android:layout_width="@dimen/pad_1dp" 
            android:layout_height="fill_parent" />
        <Button 
            android:id="@id/tab2" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="@string/newest" />
        <View 
            android:id="@id/view1" 
            android:layout_width="@dimen/pad_1dp" 
            android:layout_height="fill_parent"  />
        <Button 
            android:id="@id/tab3" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="@string/distance" />
        <View 
            android:id="@id/view1" 
            android:layout_width="@dimen/pad_1dp" 
            android:layout_height="fill_parent"  />
        <Button 
            android:id="@+id/tab4" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="@string/minimum"  />
    </LinearLayout>
</HorizontalScrollView>

Change Texts to your taste. Place in a relatveLayout and alignToParentBottom="true" Hope this helps

Prendergast answered 31/1, 2016 at 13:43 Comment(0)
H
0

Check this link: https://dzone.com/articles/scrolling-tabs-android

Wrap your TabWidget with a HorizontalScrollView and the tab set will be able to expand beyond the width of the screen and the user can drag the tabs left and right as required:

<?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:orientation="vertical"                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="none">      <TabWidget android:id="@android:id/tabs"                 android:layout_width="fill_parent"                 android:layout_height="wrap_content"/>    </HorizontalScrollView>    <FrameLayout android:id="@android:id/tabcontent"                 android:layout_width="fill_parent"                 android:layout_height="fill_parent" />  </LinearLayout></TabHost>
Helvetian answered 24/10, 2015 at 0:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.