4

I'm developing a tab based android application,I have seen that "TabActivity" class is deprecated and instead use the Fragment to achieve the same, I used the following link and develop my application, now I need to show the tab bar in the bottom, I tried few ways but could not get it work correctly,

http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/

Can some one help me on this, my tab layout 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="@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:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0"/>

            <FrameLayout
                android:id="@+android:id/realtabcontent"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
        </LinearLayout>
    </TabHost>
</LinearLayout>
K_Anas
  • 31,226
  • 9
  • 68
  • 81
Sam
  • 6,215
  • 9
  • 71
  • 90
  • You can use answer http://stackoverflow.com/questions/11827418/android-tabs-with-fragments/26477457#26477457 – Alexander Oct 21 '14 at 01:42

4 Answers4

9

First get rid of the outer LinearLayout, it's useless. Then put your TabWidget in last position of your inner LinearLayout and you're done.

gdelente
  • 776
  • 8
  • 14
1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal">
    <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:background="#ff140c14">

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

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

Works for me

Oliver.Oakley
  • 628
  • 2
  • 7
  • 23
0

assign inner linear layout orientation vertical and put the Tab Host in the last position of Linear Layout.

DjP
  • 4,537
  • 2
  • 25
  • 34
-3

Whatever, bottom Tabbar today is a UX anti-pattern

http://developer.android.com/design/patterns/pure-android.html

seufagner
  • 1,290
  • 2
  • 18
  • 25
  • 1
    And how does this answer Sam's question? Not. – NickL May 17 '13 at 09:29
  • I dont lie @NickL, only add relevant info to question – seufagner Oct 10 '13 at 05:38
  • 1
    You might be right that bottom Tabbar is a UX anti-pattern, but that does in no way answer the question. Post non-answers like suggestions and other 'relevant' info about the subject of the question to the comments, not as an answer to the question. – NickL Oct 17 '13 at 19:23