Ephemeros
Ephemeros

Reputation: 99

Android TextView text not being displayed inside tab?

Forgive my simple questions, as I'm new to android. :)

Why is the text property of the textview not displaying inside this tab?

Screen: Here

Here's my code..

MapTab2.java

package com.test.maptab2;

import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;

public class MapTab2 extends TabActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost.TabSpec spec;

        spec = getTabHost().newTabSpec("tab1");
        spec.setContent(R.id.mapstub);
        spec.setIndicator("Map");
        getTabHost().addTab(spec);

        spec = getTabHost().newTabSpec("tab2");
        spec.setContent(R.id.detailstub);
        spec.setIndicator("Detail");
        getTabHost().addTab(spec);

        getTabHost().setCurrentTab(0);

    }

}

Main.xml

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

        <!-- Tab-switch panel -->
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>

        <!-- Tab contents -->
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <!-- Map here -->
            <TextView android:id="@+id/mapstub"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="map"/>

            <!-- Other stuff -->
            <TextView android:id="@+id/detailstub"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="detail"/>

        </FrameLayout>  
    </LinearLayout>
</TabHost>

I'm trying to build my way up to displaying a map within a tab. Best to understand the basics first, I thought. :')

Upvotes: 0

Views: 1450

Answers (2)

Booger
Booger

Reputation: 18725

I actually have had more luck setting the gravity in the parent view (in this case, your LinearLayout), then setting the layout_gravity attributes in the child views (in your case, your TextViews, etc).

To get this simple example working, I would change all your "fill_parent" attributes to "wrap_content" (or 0.0dp as another alternative) - then you can start playing with the different attributes to get everything positioned exactly how you would like.

Upvotes: 1

Dhanesh Budhrani
Dhanesh Budhrani

Reputation: 190

Try adding android:gravity="center" in every TextView inside a Tab.

Upvotes: 0

Related Questions