标签内没有显示Android TextView文字?

时间:2012-02-05 12:52:47

标签: android textview tabview

原谅我的简单问题,因为我是android的新手。 :)

为什么textview的text属性不显示在此选项卡中?

屏幕:Here

这是我的代码..

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>

我正在努力建立自己在标签中显示地图的方法。我想,最好先了解基础知识。 :')

2 个答案:

答案 0 :(得分:1)

我实际上有更多运气在父视图中设置引力(在本例中为LinearLayout),然后在子视图中设置layout_gravity属性(在您的情况下,您的TextViews等)。

为了让这个简单的例子有效,我会改变你所有的&#34; fill_parent&#34;属性为&#34; wrap_content&#34; (或0.0dp作为另一种选择) - 然后你可以开始使用不同的属性来完全按照自己的意愿定位所有内容。

答案 1 :(得分:0)

尝试在标签内的每个TextView中添加android:gravity =“center”。