0

I am creating an application using TabLayout and am having problems with the display when using Intents to load different classes.

I tried creating it using the method explained in the Android Development guide seen here

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

However the problem I am having is, that I want the tabs along the bottom of the application rather than the top which I have done. The problem is that there is not enough space on screen to view the whole application so when I click a new tab and it loads its layout, it goes right through the tabs. I tried adding ScrollView but it doesn't seem to work.

Any suggestions as to how to fix this so when I load a screen I can scroll up and down the page with my tabs always appearing at the bottom and not have my layout clip through my tabs.

Any help would be much appreciated

Code for my main.xml is

<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" android:background="#92c223">

<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" />

</LinearLayout>

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

Also the code I used to swap between tabs in java is

intent = new Intent().setClass(this, tag.class); 
    spec = tabHost.newTabSpec("tag1")
            .setIndicator("tag1", res.getDrawable(R.drawable.icon))
            .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, tag2.class);
    spec = tabHost.newTabSpec("tag2")
            .setIndicator("tag2", res.getDrawable(R.drawable.icon2))
            .setContent(intent);
    tabHost.addTab(spec);
AdamM
  • 4,400
  • 5
  • 49
  • 95

1 Answers1

1

Try this

<?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>

The difference is in the FrameLayout, the height is set to wrap_content, where yours is set to fill_parent. Also he applies a layout_weight = 1 on the FrameLayout, and layout_weight = 0 on the TabWidget.

Taken from here.

Community
  • 1
  • 1
Jack
  • 9,156
  • 4
  • 50
  • 75
  • Thanks a lot, added your code in and then added ScrollLayout to it and works perfectly now. Cheers :D – AdamM Nov 22 '11 at 15:21