歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android游戲開發系統控件-TabSpec與TabHost

Android游戲開發系統控件-TabSpec與TabHost

日期:2017/3/1 10:22:58   编辑:Linux編程

Android游戲開發系統控件-TabSpec與TabHost

今天學習了另一個比較特殊的控件:TabSpec(分頁),TabHost(分頁的集合)

TabHost相當於浏覽器中分頁的集合,而TabSpec則相當於浏覽器中的每個分頁;在Android中,每一個TabSpec分頁可以是一個組件,也可以是一個布局,然後將每個分頁裝入TabHost中,TabHost即可將其中的每個分頁一並顯示出來。

創建項目:TabProject

向項目資源中添加了兩張圖片資源:bg.png與bg2.png.

功能:實現在布局中進行頁面切換

項目運行結果截圖:

修改代碼:

=>>布局文件main.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical"
  6. android:background="@drawable/bg2">
  7. <Button
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:text="@string/btn1"
  11. android:id="@+id/btn1"
  12. />
  13. <EditText
  14. android:layout_width="fill_parent"
  15. android:layout_height="wrap_content"
  16. android:text="@string/et1"
  17. android:id="@+id/et1"
  18. />
  19. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  20. android:orientation="vertical"
  21. android:layout_width="fill_parent"
  22. android:layout_height="fill_parent"
  23. android:id="@+id/mylayout"
  24. android:background="@drawable/bg"
  25. >
  26. <Button
  27. android:layout_width="fill_parent"
  28. android:layout_height="wrap_content"
  29. android:text="@string/btn2"
  30. />
  31. <EditText
  32. android:layout_width="fill_parent"
  33. android:layout_height="wrap_content"
  34. android:text="@string/et2"
  35. />
  36. </LinearLayout>
  37. </LinearLayout>
Copyright © Linux教程網 All Rights Reserved