Carnal
Carnal

Reputation: 22064

Android - Tabhost with two tabwidgets

<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">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    </FrameLayout>
</LinearLayout>

This is my layout, then in my activity which extends TabActivity I add the five different tabs like this:

    mTabHost = getTabHost();
    mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("tab1").setContent(new Intent().setClass(this, Activity1.class).putExtra("language", language)));
    mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("tab2").setContent(new Intent().setClass(this, Activity2.class).putExtra("language", language)));
    mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("tab3").setContent(new Intent().setClass(this, Activity3.class).putExtra("language", language)));
    mTabHost.addTab(mTabHost.newTabSpec("tab4").setIndicator("tab4").setContent(new Intent().setClass(this, Activity4.class).putExtra("language", language)));
    mTabHost.addTab(mTabHost.newTabSpec("tab5").setIndicator("tab5").setContent(new Intent().setClass(this, Activity5.class).putExtra("language", language)));

The problem I have is that all the five tabs are put in one row, but I want to put the three first tabs on top and then the two other tabs below the three first. How can I achieve this?

Thanks in advance.

Upvotes: 0

Views: 2304

Answers (1)

Pankaj Kumar
Pankaj Kumar

Reputation: 83028

If you are just trying to arrange your tabs(if all 5 are not displaying properly),any this is the only single reason to do as you asked (at top 3tabs and below 2 tabs), then you have better solution to put your TabView in ScrollView.

For 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: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>

Refrence : Scrolling Tabs in Android

Hope you are looking for the same.

Upvotes: 4

Related Questions