Tabwidget TabHost

实现同个页面选项卡切换的效果,tabwidget是布局中的一个标签,开发的时候比较傻逼。TabHost控件->TabWidget(必须命名为tabs)->FrameLayout(必须命名为tabcontent)。

转载个源码:

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

<TabHost android:layout_width="fill_parent"

    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/TabHost1">

    <TabWidget android:id="@android:id/tabs"

        android:layout_height="wrap_content" android:layout_width="fill_parent">

</TabWidget>

    <FrameLayout android:id="@android:id/tabcontent"

        android:paddingTop="65px" android:layout_width="fill_parent" android:layout_height="fill_parent">

        <LinearLayout android:layout_height="wrap_content" android:id="@+id/Tab1" android:orientation="vertical" android:layout_width="fill_parent">

           <EditText android:layout_height="wrap_content" android:id="@+id/edtTab1" android:layout_width="fill_parent"></EditText>

           <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btnTab1" android:text="Tab1"></Button>

        </LinearLayout>

        <LinearLayout android:layout_height="wrap_content" android:id="@+id/Tab2" android:layout_width="fill_parent" android:orientation="horizontal">

           <EditText android:layout_height="wrap_content" android:id="@+id/edtTab2" android:layout_width="wrap_content" android:layout_weight="300"></EditText>

           <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btnTab2" android:text="Tab2"></Button></LinearLayout>

    </FrameLayout>

</TabHost>

大概就是这个样子

选项卡切换时的事件,tabhost.setOnchangeListener

这边有个源码是转载的,其实老转载听惭愧

猜你喜欢

转载自csu-10086.iteye.com/blog/1913179