TabHost跟windows上的Tab标签是一样的, 在安卓中也是可以用一个Activity来存放多个页面, 用Tab来达到切换效果。
xml 文件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabhost"
>
//TAB1的布局控件
<LinearLayout
android:id="@+id/Tab1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是tab1"
/>
</LinearLayout>
//TAB2的布局控件
<LinearLayout
android:id="@+id/Tab2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是tab2"
/>
</LinearLayout>
</FrameLayout>
java代码
public class MissedHelperActivity extends TabActivity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TabHost tabs = getTabHost(); //得到TAB对象
LayoutInflater.from(this).inflate(R.layout.main, tabs.getTabContentView(), true); //载入布局
//添加第一个Tab标签
TabSpec tab1 = tabs.newTabSpec("tab1");
tab1.setIndicator("tab1");
tab1.setContent(R.id.Tab1);
tabs.addTab(tab1);
//添加第二个 Tab标签
TabSpec tab2 = tabs.newTabSpec("tab2");
tab2.setIndicator("tab2");
tab2.setContent(R.id.Tab2);
tabs.addTab(tab2);
}
}