直奔主题~!

结构如图:

第八篇 TabHost控件

main.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="fill_parent"
	 xmlns:andro 
	android:layout_height="fill_parent" android:>
	<LinearLayout android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:>
		<TextView android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:text="TextView"
			android:></TextView>
		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:
			android:text="Button"></Button>
	</LinearLayout>
	<LinearLayout android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:>
		<ImageView android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:src="@drawable/icon"
			android:></ImageView>
	</LinearLayout>
	<LinearLayout android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:>
		<AnalogClock android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:></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);  
    }
}

相关文章: