android从不同的layout添加tab页内容_tabhost




从不同的layout添加tab也内容(tabcontent)

<!--这里是layout.mian-->
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent" android:layout_height="fill_parent">
	<!--tab1的布局 -->
	<LinearLayout android:id="@+id/tab1" android:layout_width="fill_parent"
		android:layout_height="fill_parent" androidrientation="vertical">
		<TextView android:text="result" android:id="@+id/result"
			android:layout_width="fill_parent" android:layout_height="wrap_content">
		</TextView>
	</LinearLayout>
	<!--tab2的布局 -->
	<LinearLayout android:id="@+id/tab2" android:layout_width="fill_parent"
		android:layout_height="fill_parent" androidrientation="vertical">
		<AnalogClock android:id="@+id/widget36"
			android:layout_width="wrap_content" android:layout_height="wrap_content">
		</AnalogClock>
	</LinearLayout>
	<!--tab3的布局 -->
	<LinearLayout android:id="@+id/tab3" android:layout_width="fill_parent"
		android:layout_height="fill_parent" androidrientation="vertical">
		<RadioGroup android:id="@+id/widget43"
			android:layout_width="166px" android:layout_height="98px"
			androidrientation="vertical">
			<RadioButton android:id="@+id/widget44"
				android:layout_width="wrap_content" android:layout_height="wrap_content"
				android:text="RadioButton">
			</RadioButton>
			<RadioButton android:id="@+id/widget45"
				android:layout_width="wrap_content" android:layout_height="wrap_content"
				android:text="RadioButton">
			</RadioButton>
		</RadioGroup>
	</LinearLayout>

</FrameLayout>


<!--这里是layout.newgallery-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        androidrientation="vertical"  >
      <TextView android:text="result33" 
			android:id="@+id/result33"
			android:layout_width="fill_parent" 
			android:layout_height="wrap_content">
		</TextView>
</LinearLayout>



<!--这里是Main.java-->

package com.baotab;

import android.app.TabActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;

public class Main extends TabActivity implements TabContentFactory {
	/** Called when the activity is first created. */

	private LayoutInflater inflater;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitle("Tab测试");

		TabHost tabHost = getTabHost();

		LayoutInflater.from(this).inflate(R.layout.main,  tabHost.getTabContentView(),  true);
		inflater = LayoutInflater.from(this);  //创建inflater
		
		tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(R.id.tab1));
		tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab2").setContent(R.id.tab2));
		tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab3").setContent(R.id.tab3));
		tabHost.addTab(tabHost.newTabSpec("tab44").setIndicator("tab42").setContent(this));
	}

	@Override
	public View createTabContent(String paramString) {
		View view = null;
		view = inflater.inflate(R.layout.newgallery, null);
		Log.d("tabtest", "4");
		return view;
	};

}



你可能感兴趣的:(android,xml,OS)