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?
- Package CN. W. Song. UI;
- Import java. util. hashmap;
- Import java. util. Collections list;
- Import java. util. List;
- Import java. util. Map;
- Import Android. App. activity;
- Import Android. OS. Bundle;
- Import Android. View. layoutinflater;
- Import Android. View. motionevent;
- Import Android. View. view;
- Import Android. View. viewgroup;
- Import Android. widget. imageview;
- Import Android. widget. textview;
- Import CN. W. Song. widget. Navigation. rollnavigationbar;
- Import CN. W. Song. widget. Navigation. Adapter. rollnavigationbaradapter;
- /**
- * 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.
- * Be sure to import the W. Song. Android. widget-1.0.2.jar package to this project.
- * You can download it at http://download.csdn.net/detail/swadair/4103236.
- * @ Author W. Song
- * @ Version 1.0.1
- * @ Date 2012-4-22
- */
- Public class meilishuonavigationbardemoactivityextends activity {
- Private string tag = "meilishuodnavigationbardemoactivity ";
- Private string [] Title = {
"Follow", "hot", "category ",
"Like", "I "};
- Private int [] photo = {R. drawable. nav_menu_home, R. drawable. nav_menu_hot,
- R. drawable. nav_menu_category, R. drawable. nav_menu_like,
- R. drawable. nav_menu_me };
- Private int [] photoselected = {R. drawable. nav_menu_home_selected,
- R. drawable. nav_menu_hot_selected,
- R. drawable. nav_menu_category_active,
- R. drawable. nav_menu_like_active, R. drawable. nav_menu_me_selected };
- @ Override
- Protected void oncreate (bundle savedinstancestate ){
- Super. oncreate (savedinstancestate );
- Setcontentview (R. layout. meilishuonavigationbardemo_ui );
- Rollnavigationbar rnb = (rollnavigationbar) findviewbyid (R. Id. navigationbartest_ui_rollnavigationbar );
- /* Customize Dynamic Data */
- List <Map <string, Object> List = new struct list <Map <string, Object> ();
- For (INT I =
0; I <title. length; I ++ ){
- Map <string, Object> map = new hashmap <string, Object> ();
- Map. Put ("title", title [I]);
- Map. Put ("photo", photo [I]);
- Map. Put ("photoselected", photoselected [I]);
- List. Add (MAP );
- }
- /* 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 */
- Rnb. setselectermovecontinuetime (0.1f); // you can leave it unspecified. The default value is 0.1 s.
- /* Set the slide bar style (image )*/
- Rnb. setselecterdrawablesource (R. drawable. nav_menu_bg); // required
- /* Set the selected location in the navigation bar */
- Rnb. setselectedchildposition (0); // you can leave it unspecified.
- /* Navigation bar extension */
- Final mynavigationbaradapter adapter = new mynavigationbaradapter (this, list );
- Rnb. setadapter (adapter); // required
- Rnb. setnavigationbarlistener (New rollnavigationbar. navigationbarlistener (){
- /**
- * Position: The selected position.
- * View is the navigation bar.
- * Event mobile event
- */
- @ Override
- Public void onnavigationbarclick (INT position, view,
- Motionevent event ){
- Switch (event. getaction ()){
- Case motionevent. action_down: // when you press
- Break;
- Case motionevent. action_move: // moving
- Break;
- Case motionevent. action_up: // when you raise your hand
- Break;
- }
- }
- });
- }
- /**
- * Navigation bar Extension
- *
- * @ Author W. Song
- * @ Version 1.0.1
- * @ Date 2012-4-22
- */
- Class mynavigationbaradapter
Extends rollnavigationbaradapter {
- Private list <Map <string, Object> list;
- Private layoutinflater minflater;
- Public mynavigationbaradapter (activity,
- List <Map <string, Object> List ){
- Minflater = layoutinflater. From (activity );
- This. List = List;
- }
- @ Override
- Public int getcount (){
- Return list. Size ();
- }
- /**
- * Obtain each component
- *
- * @ Param position
- * Component location
- * @ Param contextview
- * Component
- * @ Param parent
- * Upper layer components
- */
- @ Override
- Public View getview (INT position, view contextview, viewgroup parent ){
- Minflater. Inflate (R. layout. Item, (viewgroup) contextview );
- Rollnavigationbar = (rollnavigationbar) parent;
- /* Obtain the component */
- Imageview = (imageview) contextview
- . Findviewbyid (R. Id. image_view );
- Textview titleview = (textview) contextview
- . Findviewbyid (R. Id. title_view );
- /* Obtain parameters */
- String title = "" + list. Get (position). Get ("title ");
- Int photo = (integer) list. Get (position). Get ("photo ");
- Int photoselected = (integer) list. Get (position). Get (
- "Photoselected ");
- /* Component setting parameters */
- // Differentiate between selected and selected images
- If (position = rollnavigationbar. getselectedchildposition () {// selected
- Imageview. setbackgroundresource (photoselected );
- } Else {// not selected
- Imageview. setbackgroundresource (photo );
- }
- Titleview. settext (title );
- Return contextview;
- }
- }
- }
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.