废话不多说,先看效果图:
package com.example.circlemenuofbottom.anim;import android.view.animation.RotateAnimation;import android.widget.RelativeLayout;/** * @author lzd * * QQ : 2622596982 * * email :www.2cto.com * * QQ :277599214 */public class MyAnimationUtils {/** * 出去的动画---顺时针出 * * @param view * 执行动画的对象 */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);}/** * 出去的动画---逆时针进 * * @param view * 执行动画的对象 */public static void animaIn(RelativeLayout view) {/* * // 顺时针进 // RotateAnimation animation = new RotateAnimation(180, // * 360,view.getWidth() / 2, view.getHeight()); // 逆时针进 RotateAnimation * animation = new RotateAnimation(-180, -360, view.getWidth() / * 2,view.getHeight()); animation.setDuration(500); * animation.setFillAfter(true); view.startAnimation(animation); */animaIn(view, 0);}/** * 出去的动画---顺时针出 * * @param view * 执行动画的对象 * @param offSetTime * 延时执行的时间 */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) {// 顺时针进// RotateAnimation animation = new RotateAnimation(180,// 360,view.getWidth() / 2, view.getHeight());// 逆时针进RotateAnimation animation = new RotateAnimation(-180, -360,view.getWidth() / 2, view.getHeight());animation.setDuration(500);animation.setStartOffset(offSetTime);animation.setFillAfter(true);view.startAnimation(animation);}}
按键的处理思路:/* * 监听菜单键,当用户点击菜单键的时候,显示和隐藏一级和二级菜单 * * 监听返回键,再按一次退出程序 */private long exitTime = 0;@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {// 菜单键的处理if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_MENU){// 如果 一级菜单显示,隐藏 全部if(isShowLevel1){MyAnimationUtils.animaOut(level);isShowLevel1 = false;if(isShowLevel2){MyAnimationUtils.animaOut(level2,120);isShowLevel2 = false;if(isShowLevel3){MyAnimationUtils.animaOut(level3,120);isShowLevel3 = false;}}}else{// 如果一级菜单式隐藏的,显示 一,二级菜单MyAnimationUtils.animaIn(level);MyAnimationUtils.animaIn(level2, 120);isShowLevel1 = true;isShowLevel2 = true;}}// 返回键if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK){if(System.currentTimeMillis() - exitTime > 2000){Toast.makeText(this, 再按一次返回键退出, Toast.LENGTH_SHORT).show();exitTime = System.currentTimeMillis();}else{finish();System.exit(0);}return true;}return super.onKeyDown(keyCode, event);}