android按Menu出现菜单的动画
private void startMenuAnimation(boolean bShow, int nGap){
if(mIsAnimationPlaying){
return;
}
mIsAnimationPlaying = true;
AnimatorListener listener = mHideListener;
if(bShow){
listener = mShowListener;
}
if(bShow){
nGap = -1 * nGap;
}
ViewPropertyAnimator.animate(mPopwinClearLayout).cancel();
if(bShow){
ViewPropertyAnimator
.animate(mPopwinClearLayout).translationXBy(nGap)
.setDuration(200).setInterpolator(new DecelerateInterpolator()).setListener(listener);
}else{
ViewPropertyAnimator
.animate(mPopwinClearLayout).translationX(0)
.setDuration(200).setInterpolator(new DecelerateInterpolator()).setListener(listener);
}
}
private AnimatorListener mHideListener = new AnimatorListener() {
@Override
public void onAnimationStart(Animator arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animator arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animator arg0) {
mPopwinClearLayout.setVisibility(View.INVISIBLE);
mIsAnimationPlaying = false;
}
@Override
public void onAnimationCancel(Animator arg0) {
// TODO Auto-generated method stub
}
};
private AnimatorListener mShowListener = new AnimatorListener() {
@Override
public void onAnimationStart(Animator arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animator arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animator arg0) {
mPopwinClearLayout.setAnimationCacheEnabled(true);
mIsAnimationPlaying = false;
}
@Override
public void onAnimationCancel(Animator arg0) {
// TODO Auto-generated method stub
}
};
调用:
显示:startMenuAnimation(true,100);
消失:startMenuAnimation(false,100);