优酷菜单栏

来源:互联网 发布:网吧软件管理系统 编辑:程序博客网 时间:2024/06/05 17:01




下面这个是menu键的



import com.dianli.util.AnimationUtils;
import com.dianli.util.MyAnimtionListener;


import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;


public class MainActivity extends Activity implements OnClickListener {
private RelativeLayout level1,level2,level3;
private boolean islevel1=true;
private boolean islevel2=true;
private boolean islevel3=true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}


private void initView() {
findViewById(R.id.home_bt).setOnClickListener(this);
findViewById(R.id.menu_bt).setOnClickListener(this);
level1 = (RelativeLayout) findViewById(R.id.level1);
level3 = (RelativeLayout) findViewById(R.id.level3);
level2 = (RelativeLayout) findViewById(R.id.level2);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_MENU){
if(islevel1){
if(MyAnimtionListener.runningAnimationCount>0){
return true;
}
long delay=0;
if(islevel3){
AnimationUtils.rotateOutAnim(level3, 0);
islevel3=false;
delay+=200;
}
if(islevel2){
AnimationUtils.rotateOutAnim(level2,delay);
islevel2=false;
delay+=200;
}
AnimationUtils.rotateOutAnim(level1, delay);
}else{
AnimationUtils.rotateInAnim(level1, 0);
AnimationUtils.rotateInAnim(level2, 200);
AnimationUtils.rotateInAnim(level3, 400);
islevel2=true;
islevel3=true;
}
islevel1=!islevel1;
return true;//消费类当前事件
}
return super.onKeyDown(keyCode, event);
}

@Override
public void onClick(View v) {
if(MyAnimtionListener.runningAnimationCount>0){
//当前动画正在执行,取消当前事件
return;
}

switch (v.getId()) {

case R.id.home_bt:
if(islevel2){
long delay=0;
if(islevel3){
AnimationUtils.rotateOutAnim(level3,delay);
islevel3=false;
delay+=200;
}
AnimationUtils.rotateOutAnim(level2,delay);
islevel2=false;
}else{
AnimationUtils.rotateInAnim(level2,0);
islevel2=true;
}
break;


case R.id.menu_bt:
if(islevel3){
AnimationUtils.rotateOutAnim(level3,0);
islevel3=false;
}else{
AnimationUtils.rotateInAnim(level3,0);
islevel3=true;
}
break;
}

}

}


//AnimationUtli类的

package com.dianli.util;


import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.RelativeLayout;


public class AnimationUtils {
//旋转隐藏动画
public static void rotateOutAnim(RelativeLayout layout,long delay){
int childCount=layout.getChildCount();
//如果隐藏,则找到所有的子view,禁用
for (int i = 0; i <childCount; i++) {
layout.getChildAt(i).setEnabled(false);
}
RotateAnimation ra=new RotateAnimation(0, -180, //开始,隐藏的角度,逆时针
Animation.RELATIVE_TO_SELF, 0.5f, //x轴的坐标
Animation.RELATIVE_TO_SELF, 1.0f);//y轴的坐标
ra.setDuration(500);//设置动画的持续时间
ra.setFillAfter(true);//设置动画停留在结束的位置
ra.setStartOffset(delay);//设置旋转的延迟时间
ra.setAnimationListener(new MyAnimtionListener());//添加监听取消连续点击事件
layout.startAnimation(ra);
}
//旋转显示的动画
public static void rotateInAnim(RelativeLayout layout,long delay){
int childCount=layout.getChildCount();
//如果隐藏,则找到所有的子view,启用
for (int i = 0; i < childCount; i++) {
layout.getChildAt(i).setEnabled(true);
}
RotateAnimation ra=new RotateAnimation(-180, 0, 
Animation.RELATIVE_TO_SELF, 0.5f, 
Animation.RELATIVE_TO_SELF, 1.0f);
ra.setDuration(500);
ra.setFillAfter(true);
ra.setStartOffset(delay);
ra.setAnimationListener(new MyAnimtionListener());
layout.startAnimation(ra);
}
}

//监听

package com.dianli.util;


import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;


public class MyAnimtionListener implements AnimationListener{

//给他个默认值
public static int runningAnimationCount=0;


@Override
public void onAnimationStart(Animation animation) {
runningAnimationCount++;
}


@Override
public void onAnimationEnd(Animation animation) {
runningAnimationCount--;
}


@Override
public void onAnimationRepeat(Animation animation) {

}


}

原创粉丝点击