tags:

views:

235

answers:

3

Hi can anybody tell how to reduce the height of tab bar and display tab bar in bottom

Thanks

A: 

Most likely you'll have to implement tabs by your own. As far as I know that's impossible with regular android tabs.

Konstantin Burov
+3  A: 

You could either

  • Build your own tab using a TableLayout at the bottom of the screen - which gives you quite a lot of flexibility

or

  • Modify use the existing TabHost/TabWidget - works in principle but I don't know how to reduce the tab bar height. Works like that:

Layout file main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TabHost android:id="@+id/tab_host"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
        <TabWidget android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@android:id/tabs"
            android:layout_gravity="bottom" />
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" android:layout_height="fill_parent" >
            <LinearLayout android:id="@+id/first_tab"
                android:orientation="vertical" android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
                <TextView android:layout_width="fill_parent"
                    android:layout_height="fill_parent" android:text="First Tab" />
                <!-- Replace TextView with your layout content for this tab -->
            </LinearLayout>
            <LinearLayout android:id="@+id/second_tab"
                android:orientation="vertical" android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
                <TextView android:layout_width="fill_parent"
                    android:layout_height="fill_parent" android:text="Second Tab" />
                <!-- Replace TextView with your layout content for this tab -->
            </LinearLayout>
            <LinearLayout android:id="@+id/third_tab"
                android:orientation="vertical" android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
                <TextView android:layout_width="fill_parent"
                    android:layout_height="fill_parent" android:text="One More Tab" />
                <!-- Replace TextView with your layout content for this tab -->
            </LinearLayout>
            <LinearLayout android:id="@+id/edit_item_text_tab"
                android:orientation="vertical" android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
        </FrameLayout>
    </TabHost>
</LinearLayout>

Source code of your activity, in this case StartActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class StartActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tab_host = (TabHost) findViewById(R.id.tab_host);
        tab_host.setup();

        TabSpec tabspec1 = tab_host.newTabSpec("TAB_1");
        tabspec1.setIndicator("Tab 1");
        tabspec1.setContent(R.id.first_tab);
        tab_host.addTab(tabspec1);

        TabSpec tabspec2 = tab_host.newTabSpec("TAB_2");
        tabspec2.setIndicator("Tab 2");
        tabspec2.setContent(R.id.second_tab);
        tab_host.addTab(tabspec2);

        TabSpec tabspec3 = tab_host.newTabSpec("TAB_3");
        tabspec3.setIndicator("Tab 3");
        tabspec3.setContent(R.id.third_tab);
        tab_host.addTab(tabspec3);

        tab_host.setCurrentTab(0);
    }
}

Turns out to look like:

alt text

Martin