直奔主题~!
结构如图:
main.xml代码:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/frameLayout1" android:layout_height="wrap_content" android:layout_width="fill_parent"></FrameLayout>
view1.xml代码:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/view1" android:layout_height="wrap_content" android:layout_width="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1" android:layout_height="fill_parent"> <TextView android:text="TextView" android:layout_height="wrap_content" android:id="@+id/textView1" android:layout_width="wrap_content"></TextView> <DatePicker android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/datePicker1"></DatePicker> <Button android:layout_height="wrap_content" android:id="@+id/button1" android:layout_width="wrap_content" android:text="Button"></Button> </LinearLayout> </FrameLayout>
view2.xml代码:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/view2" android:layout_height="wrap_content" android:layout_width="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1" android:layout_height="fill_parent" android:gravity="center"> <AnalogClock android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/analogClock1"></AnalogClock> <ImageView android:layout_width="wrap_content" android:id="@+id/imageView1" android:layout_height="wrap_content" android:src="@drawable/icon"></ImageView> </LinearLayout> </FrameLayout>
Control_TabHost_AddViewActivity.java代码:
public class Control_TabHost_AddViewActivity extends TabActivity { private TabHost th; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); th=getTabHost(); LayoutInflater lif=getLayoutInflater(); lif.inflate(R.layout.view1, th.getTabContentView(),true); LayoutInflater lif1=getLayoutInflater(); lif1.inflate(R.layout.view2, th.getTabContentView(),true); th.addTab(th.newTabSpec("view1").setIndicator("a").setContent(R.id.view1)); th.addTab(th.newTabSpec("view2").setIndicator("b").setContent(R.id.view2)); setContentView(th); } }