现在很多Android应用采用同窗口多面板(tab)的显示,web中往往被称为导航栏,作为初学者有必要学习一下,于是网上寻找到一个样例,运行后效果不错
Android4.0以后,标识TabActivity过期,不建议使用,该样例中使用FragmentActivity替换;
为了对比学习FragmentTabHost,我想先仅参考官方关于Building a Dynamic UI with Fragments,即用Fragment创建动态的用户界面,开发学习下。
首先定义布局文件sub_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<Button
android:id="@+id/button1"
android:text="@string/Tab1"
android:layout_weight="1"