TabHOST 选项卡的功能和用法

TabHOST

选项卡的功能和用法

tabhost可以方便的在窗口放置多个标签页,,每个标签页相当于一个和外部容器一样大小的组件摆放区域,通过这种方式,就可以在一个容器中放置更多组件

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

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:layout_weight="1"

    android:id="@android:id/tabhost">


    <LinearLayout

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical">

    <TabWidget

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:id="@android:id/tabs"/>

    <FrameLayout

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:id="@android:id/tabcontent">

        <!--定义第一个标签页内容-->

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:id="@+id/tb01"

            android:orientation="vertical">

            <TextView

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:text="公共课总分"/>

            <TextView

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:text="专业课总分"/>

        </LinearLayout>

        <!--定义第二个标签页-->

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:id="@+id/tb02"

            android:orientation="vertical">

            <TextView

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:text="总分合计"/>

            <TextView

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:text="总分合计01"/>

        </LinearLayout>

        <!--定义第三个标签页-->

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:id="@+id/tb03"

            android:orientation="vertical"

            >

            <TextView

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:text="录取学校"/>

            <TextView

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:text="录取专业"/>

        </LinearLayout>

    </FrameLayout>

</LinearLayout>

</TabHost>

public class MainActivity extends TabActivity {

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.tabhost);

        //获取改activity里面,tabhost组件

        TabHost th = getTabHost();

        //创建第一个tab页面

        TabHost.TabSpec tab1 = th.newTabSpec("tab1").setIndicator("分数").setContent(R.id.tb01);

        //添加第一个标签页

        th.addTab(tab1);

        TabHost.TabSpec tab2 = th.newTabSpec("tab2")

                //在标签标题上面放置图标

                .setIndicator("总分合计", getResources().getDrawable(R.drawable.mia5))

                .setContent(R.id.tb02);

        //添加第二个标签页

        th.addTab(tab2);

        TabHost.TabSpec tab3 = th.newTabSpec("tab3")

                .setIndicator("录取专业")

                .setContent(R.id.tb03);

        //添加第三个标签页

        th.addTab(tab3);



    }

}


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容