4

I want to put tabwidget on bottom like iPhone App. I know what this layout is against Google UserInterface guideline ,but i need.

so,I have read many similar post in Stackoverflow. but every post isnt working.

I want to use FragmentTabhost,without use External library (ex:ActionBarsherlock

this is my code

<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/tabcontent"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_above="@android:id/tabs" />

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_above="@android:id/tabs" />

    <TabWidget
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" />
</RelativeLayout>

and activity code is below

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_top);

    //set up FragmentTabhost
    FragmentTabHost host = (FragmentTabHost)findViewById(R.id.tabhost);
    host.setup(this,getSupportFragmentManager(),R.id.content);

    //add tabspec
    TabSpec tabSpec1 = host.newTabSpec("tab1");
    Button btn1 = new Button(this);
    btn1.setBackgroundResource(R.drawable.icon1);
    tabSpec1.setIndicator(btn1);
    Bundle bundle1 = new Bundle();
    bundle1.putString("name", "tab1");
    host.addTab(tabSpec1,SampleFragment.class,bundle1);


    TabSpec tabSpec2 = host.newTabSpec("tab2");
    Button btn2 = new Button(this);
    btn2.setBackgroundResource(R.drawable.icon2);
    tabSpec2.setIndicator(btn2);
    Bundle bundle2 = new Bundle();
    bundle2.putString("name", "tab2");
    host.addTab(tabSpec2,SampleFragment1.class,bundle2);

}

so i have tried another layout like this

<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

    <TabWidget
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="horizontal" />

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>

please help me,


Note finally I solved this ploblem. This is SupportPackage 's bug .....

try this

http://code.google.com/p/android/issues/detail?id=40035

dmnlk
  • 2,995
  • 2
  • 25
  • 30

3 Answers3

2

Try out this:

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TabWidget
    android:id="@android:id/tab"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" />

<FrameLayout
    android:id="@android:id/content"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
</RelativeLayout>
surhidamatya
  • 2,419
  • 32
  • 56
0

Try this :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost 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">
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            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>
</android.support.v4.app.FragmentTabHost>
hardartcore
  • 16,886
  • 12
  • 75
  • 101
-2

Try this, Following XML works for me very fine.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost  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" >

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.v4.app.FragmentTabHost>

Hope this will work.

Usama Sarwar
  • 8,922
  • 7
  • 54
  • 80
  • I have now pasted complete XML that works fine for me and it puts the tabhost at the bottom. Check. – Usama Sarwar Feb 07 '13 at 07:30
  • ummm... I replace xml to yours ,but tabhost is top....please upload your project? – dmnlk Feb 07 '13 at 07:46
  • Well that is neither possible nor recommended to upload whole projects, you can check any thing else you are doing in the code that is preventing the tabhost to align bottom. Uninstall the app and then install again, as this works absolutely fine in my app. – Usama Sarwar Feb 07 '13 at 07:52
  • okey,I unistalled this app and re install ,but tab is top.after,i change emulater Android ver from4.2 to 2.3.3 but not work.... – dmnlk Feb 07 '13 at 07:56
  • Then make sure that your are pasting my xml in the right file i.e `R.layout.activity_top`. – Usama Sarwar Feb 07 '13 at 08:00
  • i make new xml named testlayout.xml,and paste your code.and delete old xmlfile(b/c id is conflict)..after this,error was occured in Activity,(R.id.tabhost is nothing) so,I changed android:id="@+id/tabhost" and change other id. and Run app, tab is still top. – dmnlk Feb 07 '13 at 08:09