/**
* true:从上往下 false:从下往上
*
* @param isUpToDown true is up to down
* @param animationView 要执行动画的view
*/
public static void executeAnimation(boolean isUpToDown, View animationView) {
if (isUpToDown) {
//相对于自己的高度往下平移
TranslateAnimation translate = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
-1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
translate.setDuration(500);//动画时间500毫秒
translate.setFillAfter(true);//动画出来控件可以点击
animationView.startAnimation(translate);//开始动画
animationView.setVisibility(View.VISIBLE);//设置可见
} else {
//相对于自己的高度往上平移
TranslateAnimation translate = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
-1.0f);
translate.setDuration(500);
translate.setFillAfter(false);//设置动画结束后控件不可点击
animationView.startAnimation(translate);
animationView.setVisibility(View.GONE);//隐藏不占位置
}
}