转载于: http://blog.csdn.net/shulianghan/article/details/18233209
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<TabHost
android:id="@android:id/tabhost"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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"
android:orientation="horizontal"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="@+id/tab01"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:gravity="center"
android:textSize="23sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="text01"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/tab02"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:gravity="center"
android:textSize="23sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:text="text02"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/tab03"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:gravity="center"
android:textSize="23sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:text="text03"/>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</span>
<span style="font-size:18px;">
</span>
<span style="font-size:18px;">
</span>
<span style="font-size:18px;">
</span>
<pre name="code" class="java"><span style="font-size:18px;">import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
public class MainActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabhost = getTabHost();
TabHost.TabSpec page1 = tabhost.newTabSpec("tab1").setIndicator("第一页").setContent(R.id.tab01);
tabhost.addTab(page1);
TabHost.TabSpec page2 = tabhost.newTabSpec("tab2").setIndicator("第二页").setContent(R.id.tab02);
tabhost.addTab(page2);
TabHost.TabSpec page3 = tabhost.newTabSpec("tab3").setIndicator("第三页").setContent(R.id.tab03);
tabhost.addTab(page3);
}
}
</span>