Android-navigation bar with sliding effect

Source: Internet
Author: User

This article is transferred from:Http://blog.csdn.net/swadair/article/details/7487520
Please support the original author more!

These two days, I saw a small red block in the navigation bar at the bottom of the "beautiful saying" homepage, which was very interesting. So we made a component rollnavigationbar with similar effects.

This component can be directly used for production and application to beautify the style that everyone wants. For example, the sliding effect of the QQ navigation bar of the Android version.

Here I will cite a rollnavigationbar application demo, which will be turned into the navigation bar at the bottom of "beautiful words.

Beautiful Description: The beautiful description of the rollnavigationbar component through beautification

The following is the source code for realizing the beautiful words navigation bar in rollnavigationbar.

[Java]
View plaincopyprint?
  1. Package CN. W. Song. UI;
  2. Import java. util. hashmap;
  3. Import java. util. Collections list;
  4. Import java. util. List;
  5. Import java. util. Map;
  6. Import Android. App. activity;
  7. Import Android. OS. Bundle;
  8. Import Android. View. layoutinflater;
  9. Import Android. View. motionevent;
  10. Import Android. View. view;
  11. Import Android. View. viewgroup;
  12. Import Android. widget. imageview;
  13. Import Android. widget. textview;
  14. Import CN. W. Song. widget. Navigation. rollnavigationbar;
  15. Import CN. W. Song. widget. Navigation. Adapter. rollnavigationbaradapter;
  16. /**
  17. * This is a demo of a small application of the rollnavigationbar component. It imitates the navigation bar of the sliding effect at the bottom of the beautiful saying.
  18. * Be sure to import the W. Song. Android. widget-1.0.2.jar package to this project.
  19. * You can download it at http://download.csdn.net/detail/swadair/4103236.
  20. * @ Author W. Song
  21. * @ Version 1.0.1
  22. * @ Date 2012-4-22
  23. */
  24. Public class meilishuonavigationbardemoactivityextends activity {
  25. Private string tag = "meilishuodnavigationbardemoactivity ";
  26. Private string [] Title = {
    "Follow", "hot", "category ",
    "Like", "I "};
  27. Private int [] photo = {R. drawable. nav_menu_home, R. drawable. nav_menu_hot,
  28. R. drawable. nav_menu_category, R. drawable. nav_menu_like,
  29. R. drawable. nav_menu_me };
  30. Private int [] photoselected = {R. drawable. nav_menu_home_selected,
  31. R. drawable. nav_menu_hot_selected,
  32. R. drawable. nav_menu_category_active,
  33. R. drawable. nav_menu_like_active, R. drawable. nav_menu_me_selected };
  34. @ Override
  35. Protected void oncreate (bundle savedinstancestate ){
  36. Super. oncreate (savedinstancestate );
  37. Setcontentview (R. layout. meilishuonavigationbardemo_ui );
  38. Rollnavigationbar rnb = (rollnavigationbar) findviewbyid (R. Id. navigationbartest_ui_rollnavigationbar );
  39. /* Customize Dynamic Data */
  40. List <Map <string, Object> List = new struct list <Map <string, Object> ();
  41. For (INT I =
    0; I <title. length; I ++ ){
  42. Map <string, Object> map = new hashmap <string, Object> ();
  43. Map. Put ("title", title [I]);
  44. Map. Put ("photo", photo [I]);
  45. Map. Put ("photoselected", photoselected [I]);
  46. List. Add (MAP );
  47. }
  48. /* Set the sliding time of the slide bar. The time range is 0.1 ~ 1 S. If not in the range, the default value is 0.1 s */
  49. Rnb. setselectermovecontinuetime (0.1f); // you can leave it unspecified. The default value is 0.1 s.
  50. /* Set the slide bar style (image )*/
  51. Rnb. setselecterdrawablesource (R. drawable. nav_menu_bg); // required
  52. /* Set the selected location in the navigation bar */
  53. Rnb. setselectedchildposition (0); // you can leave it unspecified.
  54. /* Navigation bar extension */
  55. Final mynavigationbaradapter adapter = new mynavigationbaradapter (this, list );
  56. Rnb. setadapter (adapter); // required
  57. Rnb. setnavigationbarlistener (New rollnavigationbar. navigationbarlistener (){
  58. /**
  59. * Position: The selected position.
  60. * View is the navigation bar.
  61. * Event mobile event
  62. */
  63. @ Override
  64. Public void onnavigationbarclick (INT position, view,
  65. Motionevent event ){
  66. Switch (event. getaction ()){
  67. Case motionevent. action_down: // when you press
  68. Break;
  69. Case motionevent. action_move: // moving
  70. Break;
  71. Case motionevent. action_up: // when you raise your hand
  72. Break;
  73. }
  74. }
  75. });
  76. }
  77. /**
  78. * Navigation bar Extension
  79. *
  80. * @ Author W. Song
  81. * @ Version 1.0.1
  82. * @ Date 2012-4-22
  83. */
  84. Class mynavigationbaradapter
    Extends rollnavigationbaradapter {
  85. Private list <Map <string, Object> list;
  86. Private layoutinflater minflater;
  87. Public mynavigationbaradapter (activity,
  88. List <Map <string, Object> List ){
  89. Minflater = layoutinflater. From (activity );
  90. This. List = List;
  91. }
  92. @ Override
  93. Public int getcount (){
  94. Return list. Size ();
  95. }
  96. /**
  97. * Obtain each component
  98. *
  99. * @ Param position
  100. * Component location
  101. * @ Param contextview
  102. * Component
  103. * @ Param parent
  104. * Upper layer components
  105. */
  106. @ Override
  107. Public View getview (INT position, view contextview, viewgroup parent ){
  108. Minflater. Inflate (R. layout. Item, (viewgroup) contextview );
  109. Rollnavigationbar = (rollnavigationbar) parent;
  110. /* Obtain the component */
  111. Imageview = (imageview) contextview
  112. . Findviewbyid (R. Id. image_view );
  113. Textview titleview = (textview) contextview
  114. . Findviewbyid (R. Id. title_view );
  115. /* Obtain parameters */
  116. String title = "" + list. Get (position). Get ("title ");
  117. Int photo = (integer) list. Get (position). Get ("photo ");
  118. Int photoselected = (integer) list. Get (position). Get (
  119. "Photoselected ");
  120. /* Component setting parameters */
  121. // Differentiate between selected and selected images
  122. If (position = rollnavigationbar. getselectedchildposition () {// selected
  123. Imageview. setbackgroundresource (photoselected );
  124. } Else {// not selected
  125. Imageview. setbackgroundresource (photo );
  126. }
  127. Titleview. settext (title );
  128. Return contextview;
  129. }
  130. }
  131. }

Package CN. w. song. ui; </P> <p> Import Java. util. hashmap; <br/> Import Java. util. using list; <br/> Import Java. util. list; <br/> Import Java. util. map; </P> <p> Import android. app. activity; <br/> Import android. OS. bundle; <br/> Import android. view. layoutinflater; <br/> Import android. view. motionevent; <br/> Import android. view. view; <br/> Import android. view. viewgroup; <br/> Import android. widget. imageview; <br/> imp ORT android. widget. textview; <br/> Import CN. w. song. widget. navigation. rollnavigationbar; <br/> Import CN. w. song. widget. navigation. adapter. rollnavigationbaradapter; </P> <p>/** <br/> * This is a demo of a small application of the rollnavigationbar component, the navigation bar that imitates the sliding effect at the bottom of the "beautiful saying" <br/> * pay attention to W. song. android. the widget-1.0.2.jar package imports this project. <Br/> * You can download it at http://download.csdn.net/detail/swadair/4103236< br/> * @ author W. song <br/> * @ version 1.0.1 <br/> * @ date 2012-4-22 <br/> */<br/> public class meilishuonavigationbardemoactivity extends activity {<br/> private string tag = "meilishuodnavigationbardemoactivity "; <br/> private string [] Title = {"follow", "popular", "category", "like", "me "}; <br/> private int [] photo = {R. drawable. nav_menu_home, R. dra Wable. nav_menu_hot, <br/> r. drawable. nav_menu_category, R. drawable. nav_menu_like, <br/> r. drawable. nav_menu_me }; <br/> private int [] photoselected = {R. drawable. nav_menu_home_selected, <br/> r. drawable. nav_menu_hot_selected, <br/> r. drawable. nav_menu_category_active, <br/> r. drawable. nav_menu_like_active, R. drawable. nav_menu_me_selected }; </P> <p> @ override <br/> protected void oncreate (bundle savedinsta Ncestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. meilishuonavigationbardemo_ui); <br/> rollnavigationbar rnb = (rollnavigationbar) findviewbyid (R. id. navigationbartest_ui_rollnavigationbar); <br/>/* Custom Dynamic Data */<br/> List <Map <string, Object> List = new custom list <Map <string, object >>> (); <br/> for (INT I = 0; I <title. length; I ++) {<br/> Map <string, Object> map = new ha Shmap <string, Object> (); <br/> map. put ("title", title [I]); <br/> map. put ("photo", photo [I]); <br/> map. put ("photoselected", photoselected [I]); <br/> list. add (MAP); <br/>}< br/>/* set the sliding time of the slider. the time range is 0.1 ~ 1 S. If the parameter is not in the range, the default value is 0.1 s */<br/> rnb. setselectermovecontinuetime (0.1f); // you can leave this parameter Unspecified. The default value is 0.1 s. <br/>/* set the slide bar style (image) */<br/> rnb. setselecterdrawablesource (R. drawable. nav_menu_bg); // required <br/>/* set the selected position in the navigation bar */<br/> rnb. setselectedchildposition (0); // optional </P> <p>/* navigation bar extension */<br/> final mynavigationbaradapter adapter = new mynavigationbaradapter (this, list ); <br/> rnb. setadapter (adapter); // required <br/> rnb. setnavigationbarlistener (New rollnavigationbar. navigationbarlistener () {<br/>/** <br/> * position selected <br/> * view is the navigation bar <br/> * event mobile event <br/> */< br/> @ override <br/> Public void onnavigationbarclick (INT position, view view, <br/> motionevent event) {<br/> switch (event. getaction () {<br/> case motionevent. action_down: // when pressed <br/> break; <br/> case motionevent. action_move: // move in <br/> break; <br/> case motionevent. action_up: // <br/> break; <br/>}</P> <p> }); <br/>}</P> <p>/** <br/> * navigation bar extension <br/> * @ author W. song <br/> * @ version 1.0.1 <br/> * @ date 2012-4-22 <br/> */<br/> class mynavigationbaradapter extends rollnavigationbaradapter {<br/> private list <Map <string, object> list; <br/> private layoutinflater minflater; </P> <p> Public mynavigationbaradapter (activity, <br/> List <Map <string, object> List) {<br/> minflater = layoutinflater. from (activity); <br/> This. list = List; <br/>}</P> <p> @ override <br/> Public int getcount () {<br/> return list. size (); <br/>}</P> <p>/** <br/> * obtain each component <br/> * @ Param position <br/> * component location <br/> * @ Param contextview <br/> * component <br/> * @ Param parent <br/> * upper layer component <br/> */< br/> @ override <br/> Public View getview (INT position, view contextview, viewgroup parent) {<br/> minflater. inflate (R. layout. item, (viewgroup) contextview); <br/> rollnavigationbar = (rollnavigationbar) parent; <br/>/* Get component */<br/> imageview = (imageview) contextview <br/>. findviewbyid (R. id. image_view); <br/> textview titleview = (textview) contextview <br/>. findviewbyid (R. id. title_view); </P> <p>/* obtain the parameter */<br/> String title = "" + list. get (position ). get ("title"); <br/> int photo = (integer) list. get (position ). get ("photo"); <br/> int photoselected = (integer) list. get (position ). get (<br/> "photoselected "); </P> <p>/* component Setting Parameter */<br/> // differentiate between selected and selected images <br/> If (position = rollnavigationbar. getselectedchildposition () {// selected <br/> imageview. setbackgroundresource (photoselected); <br/>} else {// not selected <br/> imageview. setbackgroundresource (photo); <br/>}< br/> titleview. settext (title); </P> <p> return contextview; <br/>}</P> <p >}< br/>}

The xml configuration file directly downloads the demo project and will not be pasted out.

DownloadW. Song. Android. widget-1.0.2.jar

If you do not want to copy the code, you can directly download the demo project usewidgetdemo.

If you have any questions about the use of rollnavigationbar, you can leave a comment. I will try my best to reply to you.

W. Song. Android. widget-1.0.1.jar download scores set some high, we do not recommend that you download.

Directly import W. Song. Android. widget-1.0.2.jar to the project.


Related Article

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.