Android动画不会影响View本身的Visibility,即使本身是GONE从底部弹出动画,控件显示在了界面上,但是它本身的Visibility=GONE;或者
Visibility=VISIBLE时,使用动画从底部收回,他的属性仍然时VISIBLE,并且如果点击事件的话,你可以点击触发这个事件,虽然你看不到。
因此我们要在OnAnimationEnd中加上这段代码,
view.clearAnimation();
view.setVisibility(View.GONE);
/**
* 隐藏视图
*/
public void hideView(){
Animation.AnimationListener al = new Animation.AnimationListener()
{
@Override
public void onAnimationStart(Animation animation)
{
}
@Override
public void onAnimationEnd(Animation animation)
{
view.clearAnimation();
view .setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation)
{
}
};
Animation anim = inFromBottomAnimation(500);
anim.setAnimationListener(al);
view.startAnimation(anim);
}
/**
* 从下方进入的动画
*
* @return
*/
public Animation inFromBottomAnimation(int times)
{
Animation inFromRight = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_SELF, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(times);
inFromRight.setFillAfter(true);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}