安卓環形菜單(處理了菜單鍵和返回鍵+加入了動畫)

來源:互聯網
上載者:User

安卓環形菜單(處理了菜單鍵和返回鍵+加入了動畫)

廢話不多說,先看:

 

 

 

package com.example.circlemenuofbottom.anim;import android.view.animation.RotateAnimation;import android.widget.RelativeLayout;/** * @author lzd *  * QQ : 2622596982 *  * email :www.bkjia.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);}


 

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.