7

i am working on tabactivity.

i wanna show my tabwidget below the tabcontent(framelayout).

i done it by setting the tabwiget tab attribute as

android:gravity="bottom"

but the framelayout cant align with those tabs.

that is the tabs are shown at the bottom of the screen and overlap the framelayout

how to do that? if set some height value to the framelayout it not optimized for all screens of android. what can i do? any idea???

Praveen
  • 90,477
  • 74
  • 177
  • 219
  • Please spend a few seconds to search for existing questions. This same question was asked *yesterday*: http://stackoverflow.com/questions/2395661/android-tabs-at-the-bottom – Christopher Orr Mar 08 '10 at 13:59
  • I think Christopher's point was that if people couldn't answer the other guy's question, they probably wouldn't be able to answer yours either. In other words, there's no need to ask the question again, and instead you should try looking somewhere else. – Steve Haley Mar 08 '10 at 15:17
  • As this question is a duplicate, I will simply link to my full answer on the other question. [http://stackoverflow.com/questions/2395661/android-tabs-at-the-bottom/2710404#2710404](http://stackoverflow.com/questions/2395661/android-tabs-at-the-bottom/2710404#2710404) – stormin986 Apr 25 '10 at 23:44
  • examle code with tabs in the bottom of the screen: http://stackoverflow.com/a/23141213/2765497 – Oleksandr B Apr 18 '14 at 09:17

6 Answers6

4

The basic concept behind the Tab-Activity as follows

TabHost is a container for a tabbed window view. This object holds two children: a set of tab labels that the user clicks to select specific tab, and a FrameLayout object that displays the content of that page.

The individual element are typically controlled using this container object, rather then setting values on the child elements themselves.

TabWidget displays a list of tab labels representing each page in the parent's tab collection. The container object for this widget is TabHost. When a user selects a tab, this object sends a message to container, TabHost, to tell to switch the display page. The container TabHost is used to add labels, add the callback handler, and manage callbacks.

so adjust your layout as follows -

<?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:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

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

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="-3dip"
        android:layout_weight="0" >
    </TabWidget>
  </LinearLayout>

  </TabHost>
Swapnil Sonar
  • 2,232
  • 2
  • 29
  • 42
3

Android's examples to the rescue!

http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

Just swap tabcontent and tabs in res/layout/main.xml:

   <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="fill_parent"
            android:padding="5dp" />        
   <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

   </LinearLayout>
Ralphleon
  • 3,968
  • 5
  • 32
  • 34
  • two thinks i have to tell u. 1. its not work unless u set the gravity for ur tabwidget. 2. when the framelayout content's height i larger than the screen height the tabwidget lose its visibility from ur screen. please try ur example and let me know. – Praveen Mar 10 '10 at 08:23
3

or just use a custom one from: http://code.google.com/p/androidtabs/

it allows tabs on the bottom

reflog
  • 7,587
  • 1
  • 42
  • 47
3

Please Check the following link

There are two ways to display tabs at the bottom of a tab activity.

1) Using relative layout 2) Using Layout_weight attribute

http://justkumar.blogspot.com/2011/09/tabs-at-bottom-of-tabactivity-by.html

MduSenthil
  • 2,019
  • 3
  • 18
  • 39
0

this is the code for bottom tab

<TabWidget
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_gravity="bottom" 
android:background="#0000"
android:id="@android:id/tabs"
/>



  "android:layout_gravity="bottom" 
Anil M H
  • 3,332
  • 5
  • 34
  • 51
0

Check this

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:id="@android:id/tabhost">
<LinearLayout android:id="@+id/LinearLayout01"
android:orientation="vertical" 
android:layout_height="fill_parent"
android:layout_width="fill_parent">

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_height="fill_parent"
android:layout_width="fill_parent">

    <TabWidget 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:layout_gravity="bottom" 
android:id="@android:id/tabs">
</TabWidget>
</FrameLayout>

</LinearLayout>

surhidamatya
  • 2,419
  • 32
  • 56
Jiju Induchoodan
  • 4,236
  • 1
  • 22
  • 24