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