Skip to main content

Tabs at the bottom of TabActivity

Tabs at the bottom of TabActivity

By default tabs in Android are displayed at the top. It is a general guideline for android developers to keep the tabs at top of the Tabs based application since lot of Android mobiles are having their home, back,search buttons or touch interface at the bottom

But its purely our decision :)

There are two ways to achieve this.
  1. Using RelativeLayout
  2. Using "android:layout_weight" attibute
 1) Using RelativeLayout: .xml will look like the following.
<?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">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <FrameLayout android:id="@android:id/tabcontent"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:layout_alignParentTop="true"
             android:layout_above="@android:id/tabs" />
    <TabWidget android:id="@android:id/tabs"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_alignParentBottom="true" />
    </RelativeLayout>
</TabHost>

2)  Using "android:layout_weight" attibute
<?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"
        android:padding="5dp">

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:layout_weight="1"/>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>
    </LinearLayout>
</TabHost>
  

I have  used both approaches in my application. It is working fine without any problem.

Comments

Anonymous said…
Thank you soo much..
Angel H. said…
Muchisimas Gracias!!!!
Unknown said…
This did not work when using "android.support.v4.app.FragmentTabHost" as a TabHost.
Arief Deok said…
thx.. its helpfully

Popular posts from this blog

How to access PC's internet from Android Emulator?

PC's Internet and Android emulator If PC's Internet connection is configured with manual proxy settings, Follow the below steps. 1) You can launch your Emulator from command line with DNS server detail.  Syntax : "emulator -dns-server <DNS Server IP address> "  Example: emulator -dns-server 8.8.8.8 (8.8.8.8 is Google's Public DNS Server)    (or)   Goto Eclipse->Window->Preferences->Android->Launch and give "-dns-server " and then launch your emulator. 2) In emulator goto " Settings->Wireless & Networks->Mobile Networks-> "       2.1) Ensure that " Data roaming " is checked.       2.2) Select Access Point Names       2.3) Select an APN. (eg. Telkila )       2.4) Manually set the Proxy Server and Port details. If PC's Internet connection is configured with Automatic proxy settings, Follow above steps except step 2.4  and ensure that No proxy...

How I met Sadhguru? Part - 1

I was pursuing my Masters at College of Engineering, Guindy. In the year 2007, Isha Gramotsavam was conducted at my college grounds. There were hoardings around college of a man with white beard and turban displaying that there will be sathsang at 6 PM.  Little background about my mind set that time : To the core I hate all these saamiyaars and gurus. When somebody gave me the book "Kadhavai Thira Kaatru Varattum" by Nithyananda. I have read one page and never looked back at the book. I have understood that the words in that book makes no sense. I clearly know one thing that I dont know anything about god stuffs. But with our brought-up, I have sense to bow down to Gods and pray to them. Background is over. Within that week I happened to see that man with white beard face some three/four times. Whenever I see his face, I had a feel of pull towards him. I was always happy irrespective of the situations of life. I don't have a problem so I that I was looking for a solace...