1.布局文件
TabHost:@android:id/tabhost
FrameLayout:@android:id/tabcontent
TabWidget:@android:id/tabs
以上三个是必须的
<TabHost xmlns:Android="http://schemas.android.com/apk/res/android"
Android:id="@android:id/tabhost"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent" >
<RelativeLayout
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
Android:orientation="vertical" >
<FrameLayout
Android:id="@android:id/tabcontent"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
Android:layout_weight="1" >
</FrameLayout>
<TabWidget
Android:id="@android:id/tabs"
Android:layout_width="fill_parent"
Android:layout_height="60dp"
Android:layout_alignParentBottom="true"
Android:background="#FA83B3" />
</RelativeLayout>
</TabHost>
2.MainActivity
3.spaceviewTabHost host = getTabHost(); TabSpec tab1 = host.newTabSpec("tab1"); TabSpec tab2 = host.newTabSpec("tab2"); TabSpec tab3 = host.newTabSpec("tab3"); LinearLayout view1 = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.space_view, null); ImageView image1 =(ImageView)view1.findViewById(R.id.image123); image1.setImageResource(R.drawable.icon_2_n); TextView text1 = (TextView) view1.findViewById(R.id.TextView1); text1.setText("My"); Intent customerInfoIntent = new Intent(this, OneActivity.class); tab1.setIndicator(view1).setContent(customerInfoIntent); LinearLayout view2 = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.space_view, null); ImageView image2 =(ImageView)view2.findViewById(R.id.image123); image2.setImageResource(R.drawable.icon_3_n); TextView text2 = (TextView) view2.findViewById(R.id.TextView1); text2.setText("you"); tab2.setIndicator(view2).setContent(customerInfoIntent); LinearLayout view3 = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.space_view, null); ImageView image3 =(ImageView)view3.findViewById(R.id.image123); image3.setImageResource(R.drawable.icon_4_n); TextView text3 = (TextView) view3.findViewById(R.id.TextView1); text3.setText("our"); tab3.setIndicator(view3).setContent(customerInfoIntent); host.addTab(tab1); host.addTab(tab2); host.addTab(tab3);
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#FA83B3" android:orientation="vertical" > <ImageView android:id="@+id/image123" android:layout_width="40dp" android:layout_height="40dp" android:layout_gravity="center_horizontal" android:src="@drawable/ic_launcher" > </ImageView> <TextView android:id="@+id/TextView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="success" > </TextView> </LinearLayout>