直奔主题~!

结构如图:

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);  
    }
}
posted on 2011-09-14 17:04  Jwc  阅读(170)  评论(0编辑  收藏  举报