今天为一个系统左侧的菜单栏设置了一个点击事件,设置了translateAnimation以后发现,当位移动画结束以后,菜单里边的button的onclick事件还在,不得不感慨这点官方做得实在够脑残,于是自己又加了一个控制view显隐的代码,最后代码是这样的:
private void startHideAnimation(){ if (isexpand==true) { Animation hideAnimation = new TranslateAnimation(0, -menuLayoutWidth, 0, 0); hideAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); hideAnimation.setDuration(800); hideAnimation.setFillAfter(true); hideAnimation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub menuLayout.setVisibility(View.GONE); } }); menuLayout.startAnimation(hideAnimation);//直接设置的话,menulayout虽然从视野消失,但是原地点击的效果还在 } isexpand = false; } private void startShowAnimation(){ if (isexpand==false) { Animation showAnimation = new TranslateAnimation(-menuLayoutWidth, 0, 0, 0); showAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); showAnimation.setDuration(500); showAnimation.setFillAfter(true); menuLayout.startAnimation(showAnimation); menuLayout.setVisibility(View.VISIBLE); } isexpand = true; }