Android的TabHost不可见?为什么使用这个XML它不会显示?

3
在我的Eclipse XML编辑器中,我看到了tabhost选项卡,它看起来正是我想要的样子,但当我运行它时,我根本看不到tabHost,怎么才能确保它可见?
这是我的XML。同样,在编辑器中显示它,但运行它时却没有显示。填充它的活动目前还没有做太多事情,只是更改了两个文本字段。有什么想法吗?
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="2"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/name"
        android:layout_width="238dp"
        android:layout_column="0"
        android:layout_columnSpan="2"
        android:layout_gravity="top|left"
        android:layout_marginTop="7dp"
        android:layout_marginLeft="3dp"
        android:layout_row="0"
        android:gravity="top"
        android:maxLines="1"
        android:padding="3dp"
        android:text="Motherfucking Acer Laptop X314134"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <View
        android:layout_height="2dp"
        android:layout_width="fill_parent"
        android:layout_row="1"
        android:layout_column="0"
        android:layout_columnSpan="2"
        android:background="#FF000000"
        />

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_column="0"
        android:layout_columnSpan="2"
        android:layout_gravity="center_horizontal"
        android:layout_row="2" >

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

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

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <LinearLayout
                    android:id="@+id/Info"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/Specs"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/Fotos"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/Prijzen"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>

    <TextView
        android:id="@+id/score"
        android:layout_column="1"
        android:layout_marginRight="3dp"
        android:layout_marginTop="4dp"
        android:layout_gravity="right"
        android:layout_row="0"
        android:gravity="center_vertical"
        android:padding="3dp"
        android:text="100%"
        android:textSize="24sp" />

    <Space
        android:id="@+id/space2"
        android:layout_width="1dp"
        android:layout_height="40dp"
        android:layout_column="0"
        android:layout_gravity="left"
        android:layout_row="0" />

    <Space
        android:id="@+id/space1"
        android:layout_width="1dp"
        android:layout_height="415dp"
        android:layout_column="0"
        android:layout_gravity="left"
        android:layout_row="2" />

</GridLayout>

你如何填充布局? - a.ch.
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.product);} - Gido
1个回答

7

您需要以编程的方式完成此操作,例如:

 tabhost = (TabHost) findViewById(android.R.id.tabhost);
    tabhost.setup();
    TabSpec ts = tabhost.newTabSpec("tag1"); 
    ts.setContent(R.id.tab1);
    ts.setIndicator("First Tab");
    tabhost.addTab(ts);

    ts = tabhost.newTabSpec("tag2"); 
    ts.setContent(R.id.tab2);
    ts.setIndicator("Second Tab");  
    tabhost.addTab(ts);
    ts= tabhost.newTabSpec("tag3");
    ts.setContent(R.id.tab3);
    ts.setIndicator("Third Tab");
    tabhost.addTab(ts);

不错!但是 tag1tag2tag3 是什么意思? - Adil Malik
@AdilMalik 你好!Android开发文档对它们的解释有点模糊,但它们应该是用于跟踪选项卡的标签。 - Ant4res

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接