歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android網易頂部導航欄demo

Android網易頂部導航欄demo

日期:2017/3/1 10:15:29   编辑:Linux編程

隨著時間的推移現在的軟件要求顯示的內容越來越多,所以要在小的屏幕上能夠更好的顯示更多的內容,首先我們會想到底部菜單欄,但是有時候想網易新聞要顯示的內容太多,而且又想在主頁面全部顯示出來,所以有加了頂部導航欄,但是Android這樣的移動設備內存是受限的,那麼多界面緩存到內存中,很容易導致內存溢出,這個是比較致命的,所以不得不考慮。雖然我在之前也做過網易的頂部導航欄但是哪種方式並不好,就像使用viewpager做一些復雜的界面由於圖片占用內存過多,很容易導致內存溢出,學習了今天的內容大家做一下對比相信就有所體會。

先看一下今天要實現的效果:

至於頂部導航的具體要用到的圖片和布局大家自己調整。

由於前面已經介紹了底部菜單欄了,所以一些重復性的代碼就不貼上來了,最後我也會把下載地址貼上大家有興趣自行下載。

首先看一些頂部導航欄的布局文件:

  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. <include layout="@layout/head" />
  7. <LinearLayout
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content">
  10. <RadioGroup
  11. android:id="@+id/add_tab_group"
  12. android:layout_width="fill_parent"
  13. android:layout_height="wrap_content"
  14. android:gravity="center"
  15. android:paddingTop="6dp"
  16. android:paddingBottom="6dp"
  17. android:background="@drawable/big_button_up"
  18. android:orientation="horizontal"
  19. >
  20. <RadioButton
  21. android:id="@+id/main_tab_addExam"
  22. style="@style/MMTabButton1"
  23. android:layout_weight="1.0"
  24. android:checked="true"
  25. android:text="添加考試" />
  26. <RadioButton
  27. android:id="@+id/main_tab_myExam"
  28. style="@style/MMTabButton1"
  29. android:layout_weight="1.0"
  30. android:text="我的考試" />
  31. <RadioButton
  32. android:id="@+id/main_tab_message"
  33. style="@style/MMTabButton1"
  34. android:layout_weight="1.0"
  35. android:text="我的通知" />
  36. <RadioButton
  37. android:id="@+id/main_tab_testing"
  38. style="@style/MMTabButton1"
  39. android:layout_weight="1.0"
  40. android:text="測試" />
  41. <RadioButton
  42. android:id="@+id/main_tab_settings"
  43. style="@style/MMTabButton1"
  44. android:layout_weight="1.0"
  45. android:text="設置" />
  46. </RadioGroup>
  47. </LinearLayout>
  48. <LinearLayout
  49. android:id="@+id/container"
  50. android:layout_width="fill_parent"
  51. android:layout_height="fill_parent"
  52. android:layout_weight="1" >
  53. </LinearLayout>
  54. </LinearLayout>
Copyright © Linux教程網 All Rights Reserved