直奔主题~!

结构如图:

第九篇 TabHost深入

main.xml代码:

<?xml version="1.0" encoding="utf-8"?>
	<FrameLayout
	xmlns:andro
	 android:
		android:layout_height="wrap_content" android:layout_width="fill_parent"></FrameLayout>

view1.xml代码:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:andro
	android:
	android:layout_width="fill_parent">
	<LinearLayout android:layout_width="fill_parent" android:>
		<TextView android:text="TextView" android:layout_height="wrap_content" android:></TextView>
		<DatePicker android:layout_width="wrap_content" android:layout_height="wrap_content" android:></DatePicker>
		<Button android:layout_height="wrap_content" android:></Button>
	</LinearLayout>
</FrameLayout>

view2.xml代码:

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

    }
}

 

相关文章: