TabHost

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

   
                TabHost 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);


3.spaceview

<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>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值