Android Project actual combat imitation NetEase top navigation bar effect _android

Source: Internet
Author: User
Tags stub

Over time now the software requirements show more and more content, so in the small screen can better display more content, first of all we will think of the bottom menu bar, but sometimes think NetEase news to show too much content, but also want to show all the main page out, so have added the top navigation bar, But mobile devices such as Android are limited in memory, so the multiple interface caching in memory can easily lead to memory overflow, which is more fatal, so it has to be considered. Although I have also done before NetEase's top navigation bar but the way is not good, just like using Viewpager to do some complex interface because the picture occupies too much memory, it is easy to cause memory overflow, learning today's content we do a comparison believe that some experience.
Let's take a look at the effect you want to achieve today:

For the top navigation of the specific to use the picture and layout of everyone to adjust their own.

Because of the previous introduction of the bottom menu bar, so some of the repetitive code will not be posted, and finally I will download the address posted on the interest of their own download.

First look at some of the top navigation bar layout files:

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical " > <include layout= "@layout/head"/> <linearlayout android:layout_width= "Fill_parent" android:layout  
    _height= "Wrap_content" > <radiogroup android:id= "@+id/add_tab_group" android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:gravity= "center" android:paddingtop= "6DP" Android:paddin Gbottom= "6DP" android:background= "@drawable/big_button_up" android:orientation= "Horizontal" > &L T 
     RadioButton android:id= "@+id/main_tab_addexam" style= "@style/mmtabbutton1" android:layout_weight= "1.0"  
     Android:checked= "true" android:text= "add Quiz"/> <radiobutton android:id= "@+id/main_tab_myexam" style= "@style/mmtabbutton1"
     Android:layout_weight= "1.0" android:text= "My exams/> <radiobutton android:id=" @+id/mai 
 
    N_tab_message "style=" @style/mmtabbutton1 "android:layout_weight= 1.0" android:text= "my Notice"/> <radiobutton android:id= "@+id/main_tab_testing" style= "@style/mmtabbutton1" android:layout_weight= "1. 0 "android:text=" test "/> <radiobutton android:id=" @+id/main_tab_settings "style=" @style/mmtabb Utton1 "android:layout_weight=" 1.0 "android:text= settings"/> </RadioGroup> </linearlayout& 
   
 Gt <linearlayout android:id= "@+id/container" android:layout_width= fill_parent "android:layout_height=" Fill_paren 
 T "android:layout_weight=" 1 "> </LinearLayout> </LinearLayout>

Specific width style everyone can adjust and then look at the core class:

Import Android.app.ActivityGroup; 
Import Android.app.AlertDialog; 
Import Android.app.LocalActivityManager; 
Import Android.content.Context; 
Import Android.content.DialogInterface; 
Import android.content.Intent; 
Import Android.os.Bundle; 
Import android.view.KeyEvent; 
Import Android.view.View; 
Import android.view.animation.Animation; 
Import Android.view.animation.AnimationUtils; 
Import Android.widget.Button; 
Import Android.widget.LinearLayout; 
Import Android.widget.RadioGroup; 
Import Android.widget.TextView; 
 
Import Android.widget.RadioGroup.OnCheckedChangeListener; 
 public class Addexamactivity extends Activitygroup {protected Button btn_lefttop, btn_righttop; 
  
 protected TextView Tv_head; 
 private static Localactivitymanager manager; 
 Private Radiogroup Radiogroup; 
 private static LinearLayout container; 
  
 public static context context; @Override protected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method stub super.oncreatE (savedinstancestate); 
  Setcontentview (R.layout.addexam); 
  Context=this; 
   
  Inithead (); 
  Manager=getlocalactivitymanager (); 
  Container= (LinearLayout) Findviewbyid (R.id.container); 
   
  radiogroup= (Radiogroup) This.findviewbyid (R.id.add_tab_group); 
  Container.removeallviews (); Container.addview (manager.startactivity) ("Page_0", new Intent (context, Myexamactivity.class). Addflags (Intent.fla 
   
  g_activity_clear_top)). Getdecorview ()); Radiogroup.setoncheckedchangelistener (New Oncheckedchangelistener () {@Override public void oncheckedchanged ( Radiogroup Group, int checkedid) {//TODO auto-generated Method stub switch (checkedid) {case r.id.main_t 
     ab_addexam://Add exam container.removeallviews (); Container.addview (manager.startactivity) ("Page_0", new Intent (context, Myexamactivity.class). Addflags (inte Nt. 
     flag_activity_clear_top)). Getdecorview ()); 
    Break Case r.id.main_tab_myexam://my exams. 
     Container.removeallviews (); Container.addview (manager.startactivity) ("Page_1", new Intent (context, Mymessageactivity.class). Addflags (I Ntent. 
     flag_activity_clear_top)). Getdecorview ()); 
    Break 
     Case r.id.main_tab_message://My notice container.removeallviews (); Container.addview (manager.startactivity) ("page_2", new Intent (context, Settingactivity.class). Addflags (Int Ent. 
     flag_activity_clear_top)). Getdecorview ()); 
    Break 
     Case r.id.main_tab_testing://Test container.removeallviews (); Container.addview (manager.startactivity) ("Page_3", new Intent (context, Testingactivity.class). Addflags (Int Ent. 
     flag_activity_clear_top)). Getdecorview ()); 
    Break 
     Case r.id.main_tab_settings://set Container.removeallviews (); Container.addview (manager.startactivity) ("Page_4", new Intent (context, Myexamactivity.class). Addflags (inte Nt. Flag_activity_clear_top)) 
       . Getdecorview ()); 
    Break 
     Default://tabhost.setcurrenttabbytag ("my Exams"); 
    Break 
 } 
   } 
  }); public static void Changeto () {Animation Slideleftin = animationutils.loadanimation (Context, r.anim.slide_bottom_in 
   
  _no_alpha); 
  Container.removeallviews (); Container.addview (manager.startactivity) ("Page_4", new Intent (context, Myexamactivity.class). Addflags (Intent.fla 
  g_activity_clear_top)). Getdecorview ()); 
 Container.startanimation (Slideleftin); 
  } protected void Inithead () {btn_lefttop = (Button) Findviewbyid (r.id.btn_lefttop); 
  Btn_righttop = (Button) Findviewbyid (r.id.btn_righttop); 
   
  Tv_head = (TextView) Findviewbyid (R.id.tv_head); 
  Btn_lefttop.setvisibility (view.invisible); 
 Tv_head.settext ("Add Test"); @Override public boolean onKeyDown (int keycode, keyevent event) {//TODO auto-generated method stub if ( KeyCode = = keyevent.keycode_back) {Alertdialog.builder Builder = new AleRtdialog.builder (GetParent ()); Builder.setmessage (Are you sure you want to quit?) "). Setcancelable (False). Setpositivebutton (OK), new Dialoginterface.onclicklistener () {Pub 
         LIC void OnClick (dialoginterface dialog, int id) {finish (); 
        System.exit (0); }). Setnegativebutton ("Back", new Dialoginterface.onclicklistener () {public void OnClick (D 
        Ialoginterface dialog, int id) {dialog.cancel (); 
   } 
       }); 
   Alertdialog alert = Builder.create (); 
   Alert.show (); 
  return true; 
 Return Super.onkeydown (KeyCode, event);  } 
}

Here inherited Activitygroup, no use of friends from Baidu search under the understanding.
Using the Localactivitymanager promoter activity, the context and linearlayout use static static, because of the abnormal requirements that I have to do, I hope you do not set these two variables into a static , because the static life cycle is very long, especially if the context is not set to static, so that the current activity is difficult to be destroyed. In fact, the use of tabhost can be achieved, but why did not use tabhost I believe that we all understand, if not consider the memory I will use.

The above is the entire content of this article, I hope to give you a reference, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.