Android网易顶部导航栏demo


随着时间的推移现在的软件要求显示的内容越来越多,所以要在小的屏幕上能够更好的显示更多的内容,首先我们会想到底部菜单栏,但是有时候想网易新闻要显示的内容太多,而且又想在主页面全部显示出来,所以有加了顶部导航栏,但是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.      
  8.   <LinearLayout   
  9.     android:layout_width="fill_parent"  
  10.     android:layout_height="wrap_content">  
  11.             <RadioGroup  
  12.                 android:id="@+id/add_tab_group"  
  13.                 android:layout_width="fill_parent"  
  14.                 android:layout_height="wrap_content"  
  15.                 android:gravity="center"  
  16.                 android:paddingTop="6dp"  
  17.                 android:paddingBottom="6dp"  
  18.                 android:background="@drawable/big_button_up"  
  19.                 android:orientation="horizontal"  
  20.                  >  
  21.   
  22.                 <RadioButton  
  23.                     android:id="@+id/main_tab_addExam"  
  24.                     style="@style/MMTabButton1"  
  25.                     android:layout_weight="1.0"  
  26.                     android:checked="true"  
  27.                     android:text="添加考试" />  
  28.   
  29.                 <RadioButton  
  30.                     android:id="@+id/main_tab_myExam"  
  31.                     style="@style/MMTabButton1"  
  32.                     android:layout_weight="1.0"  
  33.                      
  34.                     android:text="我的考试" />  
  35.   
  36.                 <RadioButton  
  37.                     android:id="@+id/main_tab_message"  
  38.                     style="@style/MMTabButton1"  
  39.                     android:layout_weight="1.0"  
  40.                     android:text="我的通知" />  
  41.   
  42.                 <RadioButton  
  43.                     android:id="@+id/main_tab_testing"  
  44.                     style="@style/MMTabButton1"  
  45.                     android:layout_weight="1.0"  
  46.                     android:text="测试" />  
  47.                 <RadioButton  
  48.                     android:id="@+id/main_tab_settings"  
  49.                     style="@style/MMTabButton1"  
  50.                     android:layout_weight="1.0"  
  51.                     android:text="设置" />  
  52.             </RadioGroup>  
  53.               
  54.        </LinearLayout>  
  55.          
  56.     <LinearLayout  
  57.         android:id="@+id/container"  
  58.         android:layout_width="fill_parent"  
  59.         android:layout_height="fill_parent"  
  60.         android:layout_weight="1" >  
  61.     </LinearLayout>  
  62. </LinearLayout>   
  • 1
  • 2
  • 下一页

相关内容