选项卡在android中重叠内容

时间:2014-08-27 05:57:47

标签: java android xml tabs

我正在创建一个包含4个标签的项目,但是当我转到第二个标签时,第一个标签的内容仍然存在,当我转到第三个标签时,前两个标签的内容仍然存在。

标签主xml:

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

        </FrameLayout>


</LinearLayout>
</TabHost>

tabmain的java代码:

package com.igloo.icebucket;





import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class TabMain extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_main);
        TabHost th=(TabHost) findViewById(android.R.id.tabhost);
        th.setup();
        TabSpec t1=th.newTabSpec("Videos");
        TabSpec t2=th.newTabSpec("About challenge");
        TabSpec t3=th.newTabSpec("About ALS");
        TabSpec t4=th.newTabSpec("About IGLOO");


        t1.setIndicator("Videos",getResources().getDrawable(R.drawable.ic_launcher));
        Intent i1=new Intent(getApplicationContext(),VideoActivity.class);
        t1.setContent(i1);

        t2.setIndicator("About challenge",getResources().getDrawable(R.drawable.ic_launcher));
        Intent i2=new Intent(getApplicationContext(),AboutChallenge.class);
        t2.setContent(i2);

        t3.setIndicator("About ALS",getResources().getDrawable(R.drawable.ic_launcher));
        Intent i3=new Intent(getApplicationContext(),Aboutals.class);
        t3.setContent(i3);

        t4.setIndicator("About IGLOO",getResources().getDrawable(R.drawable.ic_launcher));
        Intent i4=new Intent(getApplicationContext(),Aboutigloo.class);
        t4.setContent(i4);


        th.addTab(t1);
        th.addTab(t2);
        th.addTab(t3);
        th.addTab(t4);

}
}

第一个标签的xml:

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0067ae"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".VipActivity" >

    <LinearLayout
        android:id="@+id/titlebar"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_centerHorizontal="true"
        android:background="#e2e2e2"
        android:gravity="center_horizontal|center_vertical"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="@string/videos"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="#0067ae" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/titlebar"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/videoList"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginBottom="15dp"
            android:layout_weight="1"
            android:background="#f8f8f8" >
        </ListView>
    </LinearLayout>



</RelativeLayout>

第二个标签的xml:

<LinearLayout
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/root_aboutchallenge"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ABOUT CHALLENGE"
        />
</LinearLayout>

第三个标签的xml:

<LinearLayout
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/root_aboutals"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ABOUT ALS"
        />
</LinearLayout>

第四个标签的xml:

<LinearLayout
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/root_aboutigloo"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ABOUT IGLOO"
        />
</LinearLayout>

请帮助!!

0 个答案:

没有答案