Demo apk Download: Link: http://pan.baidu.com/s/1eQgurse Password: g91r
:
Animation Effect Introduction:
1. Click on the "+" button on the Actionbar, the menu pops up from above (with bounce effect);
2. Click "+" again, click on the blank area or click the Back button, the menu to the top of the collection;
3. Click the button on the pop-up, the button zooms in, the other buttons zoom out, and the menu overall fades out.
Main code:
1.Activity.
/** * Parody animation popup */public class Mainactivity extends Actionbaractivity {//for marking the top position of the page private View TopView; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); TopView = Findviewbyid (r.id.main_top); } private Popupwindow Popupwindow; private int Line1deltay, Line2deltay; Faux-letter More popup private void ShowPopup () {if (Popupwindow = = null) {View Contentview = layoutinflater.fr Om (this). Inflate (r.layout.yixin_pop_layout, NULL); Click the blank area to close View Blankview = Contentview.findviewbyid (R.id.yixin_more_blank); View blankView2 = Contentview.findviewbyid (R.ID.YIXIN_MORE_BLANK2); Inititems (Contentview); measurement height int line2height = viewutils.getviewmeasuredheight (Itemviews[0]); Line1deltay =-getactionbarheight ()-40; Line2deltay = Line1deltay-line2height; BlAnkview.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View V ) {dismisspopup (); } }); Blankview2.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (Vie W v) {dismisspopup (); } }); Popupwindow = new Popupwindow (Contentview, Screenutils.getscreenw (This), screenutils.getscreenh (this)); Arbitrarily set a drawable as background popupwindow.setbackgrounddrawable (new colordrawable ()); } if (!popupwindow.isshowing ()) {Popupwindow.showasdropdown (topView, 0, 0); for (int i = 0; i < itemviews.length; i++) {if (I < 3) {//First line Itemviews[i].startanimation (Animationhelper.createpopupanimin (this, line1deltay)); } else {//second row Itemviews[i].startanimation (Animationhelper.createpopupanimin (this, line2deltay)); }} popupwindow.getcontentview (). Startanimation (Animationhelper.createpopupbgfadeinanim ()); }} private void Dismisspopup () {if (Popupwindow = = NULL | |!popupwindow.isshowing ()) {return; } viewgroup Contentview = (viewgroup) Popupwindow.getcontentview (); Contentview.startanimation (Animationhelper.createpopupbgfadeoutanim (animationhelper.time_out)); for (int i = 0; i < itemviews.length; i++) {if (I < 3) {//First line Itemviews[i ].startanimation (Animationhelper.createpopupanimout (this, line1deltay)); } else {//second row itemviews[i].startanimation (Animationhelper.createpopupanimout (This, Line2del TaY)); }}//animation at the end of the Hide Popupwindow contentview.postdelayed (new Runnable () {@Override PUBlic void Run () {Popupwindow.dismiss (); }}, Animationhelper.time_out + 10); } private view[] itemviews; Initialize the button on Popupwindow private void Inititems (View parent) {int[] viewids = new INT[]{R.ID.YIXIN_MORE_ITEM1, r.id . yixin_more_item2, R.id.yixin_more_item3, R.id.yixin_more_item4, R.ID.YIXIN_MORE_ITEM5, R.id.yixin_more_ite M6}; Itemviews = new View[viewids.length]; int itemwidth = SCREENUTILS.GETSCREENW (this)/3; Onclickimpl L = new Onclickimpl (); for (int i = 0; i < viewids.length; i++) {int id = viewids[i]; Itemviews[i] = Parent.findviewbyid (ID); Gridlayout.layoutparams p = (gridlayout.layoutparams) itemviews[i].getlayoutparams (); P.width = Itemwidth; Itemviews[i].setlayoutparams (P); Itemviews[i].setonclicklistener (l); }} Private class Onclickimpl implements View.onclicklistener {@Override PUBlic void OnClick (View v) {final int viewId = V.getid (); Background animation Popupwindow.getcontentview (). Startanimation (Animationhelper.createpopupbgfadeoutanim (AnimationHelper.TIM E_out_click)); Hide Popupwindow v.postdelayed at end of animation (new Runnable () {@Override public void run () { Popupwindow.dismiss (); Response Click event Handleevent (viewId) at the end of the animation; }}, Animationhelper.time_out_click + 10); button animation for (View item:itemviews) {if (Item.getid () = = V.getid ()) {//click button , Enlarge item.startanimation (Animationhelper.createpopupitembiggeranim (mainactivity.this)); } else {//other buttons, narrow item.startanimation (Animationhelper.createpopupitemsmalleranim (Ma Inactivity.this)); }}}}//popupwindow Click event on the button private void handleevent (int viewId) {Toast.maketext (this, "clicked button:" + ViewId, Toast.length_short). Show (); } private int Getactionbarheight () {return Getsupportactionbar (). GetHeight (); @Override public boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.menu_main, menu) ; return true; } @Override public boolean onoptionsitemselected (MenuItem item) {int id = item.getitemid (); if (id = = R.id.action_more) {if (Popupwindow = = NULL | |!popupwindow.isshowing ()) {ShowPopup () ; } else {dismisspopup (); } return true; } return super.onoptionsitemselected (item); }//When you click the back key, if Popupwindow is a display state, close it @Override public void onbackpressed () {if (Popupwindow! = null &&A mp Popupwindow.isshowing ()) {dismisspopup (); Return } super.onbackpressed (); }}
2. Animation Tool class.
/** * Animationhelper */public class Animationhelper {/** * time to enter animation */public static final int time_in = 30 0; /** * Bounce animation time after entering animation */public static final int time_in_back = 100; /** * Time to exit animation */public static final int time_out = 300; /** * The time to exit the animation after clicking on the Popupwindow menu */public static final int time_out_click = 500; /** * Popupwindow on menu Enter animation */public static Animation Createpopupanimin (context context, int fromydelta) { Animationset animationset = new Animationset (context, NULL);//Animationset.setinterpolator (new Bounceinterpolator ()); Bounce Animationset.setfillafter at the end (true); Mobile Translateanimation Translateanim = new Translateanimation (0, 0, Fromydelta, 20); Translateanim.setduration (time_in); Animationset.addanimation (Translateanim); Rebound effect Translateanimation translateAnim2 = new Translateanimation (0, 0, 0,-20); Translateanim2.setstartoffset (Time_IN); Translateanim2.setduration (Time_in_back); Animationset.addanimation (TRANSLATEANIM2); return animationset; }/** * Popupwindow on menu Leave animation */public static Animation Createpopupanimout (context context, int toydelta) { Animationset animationset = new Animationset (context, NULL); Animationset.setfillafter (TRUE); Translateanimation Translateanim = new Translateanimation (0, 0, 0, Toydelta); Translateanim.setduration (time_out); Animationset.addanimation (Translateanim); return animationset; }/** * Popupwindow background into animation (transparency gradient) */public static Animation Createpopupbgfadeinanim () {Alphaanimatio n anim = new Alphaanimation (0, 1.0f); Anim.setduration (time_in); Anim.setfillafter (TRUE); return anim; }/** * Popupwindow background off animation (transparency gradient) */public static Animation Createpopupbgfadeoutanim (int duration) { Alphaanimation anim = new Alphaanimation (1.0f, 0); Anim.setduration (duration); Anim.setfillafter (TRUE); return anim; }/** * Popupwindow button click Animation */public static Animation Createpopupitembiggeranim (context context) {Ani Mationset animationset = new Animationset (context, NULL); Animationset.setfillafter (TRUE); Zoom in (set the center point of the Zoom to its center) scaleanimation Scaleanim = new Scaleanimation (1.0f, 2.0f, 1.0f, 2.0f, Animation . Relative_to_self, 0.5f, Animation.relative_to_self, 0.5f); Scaleanim.setduration (Time_out_click); Animationset.addanimation (Scaleanim); Gradient alphaanimation Alphaanim = new Alphaanimation (1.0f, 0); Alphaanim.setinterpolator (New Accelerateinterpolator ()); Alphaanim.setduration (Time_out_click); Animationset.addanimation (Alphaanim); return animationset; }/** * Popupwindow button click animation of other buttons */public static Animation Createpopupitemsmalleranim (context context) { Zoom in (set the center point of the Zoom to its center)Scaleanimation Scaleanim = new Scaleanimation (1.0f, 0, 1.0f, 0, Animation.relative_to_self, 0.5f, Animation . Relative_to_self, 0.5f); Scaleanim.setduration (Time_out_click); Scaleanim.setfillafter (TRUE); return Scaleanim; }}
======
Full source Download:
http://download.csdn.net/detail/books1958/8623665
Android: Beautifully animated popup (faux-letter)