polyakovsky
polyakovsky

Reputation: 317

Android: layout does not appear as tab content

I have some tabs based on layouts with their own xml description, but when i tried to set tab content i got such a result:

http://img266.imageshack.us/img266/1787/appnavihist.jpg

(white field with text is a part of home.xml layout). Here's some code:

    TabSpec spec = tabHost.newTabSpec("home").setIndicator("Home").setContent(R.id.LinearLayout_home);
    tabHost.addTab(spec);

main.xml:

<?xml version="1.0" encoding="utf-8"?>  

<LinearLayout android:id="@+id/LinearLayout_root" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">

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

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

</LinearLayout>

Upvotes: 1

Views: 1981

Answers (2)

Amitabha Biswas
Amitabha Biswas

Reputation: 3291

its working.. i did try..

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

but i get xactly which my requirement with this

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

[ to remove extra space below of tabhost]

Upvotes: 0

Konstantin Burov
Konstantin Burov

Reputation: 69228

I think your problem is with layout that contains tabwidget element, try adding android:orientation="vertical" property to the tabwidget container:

<LinearLayout android:id="@+id/LinearLayout_root" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:orientation="vertical">

Default android template for TabActivity looks like this:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost"
android:layout_width="match_parent" android:layout_height="match_parent">
    <LinearLayout android:orientation="vertical"
    android:layout_width="match_parent" android:layout_height="match_parent">
        <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent"
            android:layout_height="wrap_content" android:layout_weight="0" />
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="match_parent" android:layout_height="0dip"
            android:layout_weight="1"/>
    </LinearLayout>
</TabHost>

I guess it should work for you as well.

Upvotes: 2

Related Questions