Android ring menu (processed menu keys and return keys + added animations)

Source: Internet
Author: User

Android ring menu (processed menu keys and return keys + added animations)

Not much nonsense. first look at it:

 

 

  
 

Package com. example. circlemenuofbottom. anim; import android. view. animation. rotateAnimation; import android. widget. relativeLayout;/*** @ author lzd *** QQ: 2622596982 *** email: www.bkjia.com ** QQ chat group: 277599214 */public class MyAnimationUtils {/*** exit animation --- clockwise output ** @ param view * animation object */public static void animaOut (RelativeLayout view) {/** RotateAnimation animation = new RotateAnimation (0,180, * view. getWidth ()/2, view. getHeight (); animation. setDuration (500); * animation. setFillAfter (true); view. startAnimation (animation); */animaOut (view, 0 );} /*** go-out animation --- enter ** @ param view * the animation object */public static void animaIn (RelativeLayout view) counterclockwise) {/** // clockwise // RotateAnimation animation = new RotateAnimation (180, // * 360, view. getWidth ()/2, view. getHeight (); // enter RotateAnimation * animation = new RotateAnimation (-180,-360, view. getWidth ()/* 2, view. getHeight (); animation. setDuration (500); * animation. setFillAfter (true); view. startAnimation (animation); */animaIn (view, 0 );} /*** exit animation --- clockwise output ** @ param view * the animation execution object * @ param offSetTime * The Time of delayed execution */public static void animaOut (RelativeLayout view, int offSetTime) {RotateAnimation animation = new RotateAnimation (0,180, view. getWidth ()/2, view. getHeight (); animation. setDuration (500); animation. setStartOffset (offSetTime); animation. setFillAfter (true); view. startAnimation (animation);} public static void animaIn (RelativeLayout view, int offSetTime) {// clockwise forward // RotateAnimation animation = new RotateAnimation (180, // 360, view. getWidth ()/2, view. getHeight (); // enter RotateAnimation animation = new RotateAnimation (-180,-360, view. getWidth ()/2, view. getHeight (); animation. setDuration (500); animation. setStartOffset (offSetTime); animation. setFillAfter (true); view. startAnimation (animation );}}

 

Handling of buttons:

 

/** Listen to the menu key. When you click the menu key, the first and second menus are displayed and hidden ** listen to the Return key, and then press exit program once */private long exitTime = 0; @ Overridepublic boolean onKeyDown (int keyCode, KeyEvent event) {// process the menu key if (event. getAction () = KeyEvent. ACTION_DOWN & keyCode = KeyEvent. KEYCODE_MENU) {// if the first-level menu is displayed, hide all if (isShowLevel1) {MyAnimationUtils. animaOut (level); isShowLevel1 = false; if (isShowLevel2) {MyAnimationUtils. animaOut (level2, 120); isShowLevel2 = false; if (isShowLevel3) {MyAnimationUtils. animaOut (level3, 120); isShowLevel3 = false ;}} else {// if the level-1 menu is hidden, display level-1 and level-2 menu MyAnimationUtils. animaIn (level); MyAnimationUtils. animaIn (level2, 120); isShowLevel1 = true; isShowLevel2 = true ;}// return key if (event. getAction () = KeyEvent. ACTION_DOWN & keyCode = KeyEvent. KEYCODE_BACK) {if (System. currentTimeMillis ()-exitTime> 2000) {Toast. makeText (this, press the return key again to exit, Toast. LENGTH_SHORT ). show (); exitTime = System. currentTimeMillis ();} else {finish (); System. exit (0);} return true;} return super. onKeyDown (keyCode, event );}


 

 

 

 

 

 

 

 

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.