读书人

Tabhost嵌套以及Tab中兑现多个Activit

发布时间: 2012-06-21 13:42:41 作者: rapoo

Tabhost嵌套以及Tab中实现多个Activity跳转的使用
在网上查了一些资料,明白了Tabhost嵌套和Tab里实现多个Activity的跳转原理,自己做了一个demo,源码 如下:

  • <?xml version="1.0" encoding="utf-8"?> <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"
  • android:background="@drawable/ch"> <LinearLayout android:orientation="vertical"
  • android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabWidget android:id="@android:id/tabs"
  • android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
  • <FrameLayout android:id="@android:id/tabcontent" android:layout_weight="1" android:layout_width="fill_parent"
  • android:layout_height="fill_parent" /> </LinearLayout>
  • </TabHost>
  • ////////////////////////////////////////////////////////
  • <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  • android:layout_width="match_parent" android:layout_height="match_parent"
  • android:orientation="vertical" > <TextView
  • android:id="@+id/text1" android:layout_width="wrap_content"
  • android:layout_height="wrap_content" android:text="这是tab的第二个界面">
  • </TextView>
  • </LinearLayout>
  • //////////////////////////////////////////////////////
  • <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  • android:layout_width="match_parent" android:layout_height="match_parent"
  • android:orientation="vertical" > <TextView
  • android:id="@+id/text1" android:layout_width="wrap_content"
  • android:layout_height="wrap_content" android:text="这是tab的第一个界面">
  • </TextView> <Button android:id="@+id/btn"
  • android:layout_width="wrap_content" android:layout_height="wrap_content"
  • android:text="跳转 "/>
  • </LinearLayout>
  • //////////////////////////////////////////////////////
  • <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  • android:id="@+id/mytabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"
  • android:background="@drawable/yt"> <LinearLayout android:orientation="vertical"
  • android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- 注意FrameLayout\TabWidget标签的位置-->
  • <FrameLayout android:id="@android:id/tabcontent"
  • android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="fill_parent" >
  • <TextView android:id="@+id/widget59"
  • android:layout_width="wrap_content" android:layout_height="wrap_content"
  • android:text="苹果IOS?" android:layout_alignParentTop="true"
  • android:layout_centerHorizontal="true" >
  • </TextView> <TextView
  • android:id="@+id/widget60" android:layout_width="wrap_content"
  • android:layout_height="wrap_content" android:text="谷歌Android"
  • android:layout_alignParentTop="true" android:layout_alignParentRight="true"
  • > </TextView>
  • </FrameLayout> <TabWidget android:id="@android:id/tabs"
  • android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
  • </LinearLayout> </TabHost>

    ///////////////////////////////////////////////////////////////待会补上效果图~


  • 读书人网 >移动开发

    热点推荐