3.9 TabSpec与TabHost
TabHost类官方文档地址:http://developer.android.com/reference/android/widget/TabHost.html
Android 实现tab视图有2种方法,一种是在布局页面中定义<tabhost>标签,另一种就是继承tabactivity.但是我比较喜欢第二种方式,应为如果页面比较复杂的话你的XML文件会写得比较庞大,用第二种方式XML页面相对要简洁得多。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/mm1" android:orientation="vertical" > <Button android:id="@+id/btn" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第一个Tab" /> <EditText android:id="@+id/et" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="第二个Tab" /> <LinearLayout android:id="@+id/myLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/mm2" android:orientation="vertical" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第三个Tab" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="第三个Tab" /> </LinearLayout> </LinearLayout>