动画后按钮 alpha 未恢复
button alpha not restored after animation
我想知道为什么在我的按钮 giftFinal 下面的代码中没有取回他的 alpha。执行后按钮文本不可见。甚至没有设置文本颜色或背景颜色:
final float alpha=giftFinal.getAlpha();
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setStartOffset(30000);
fadeOut.setDuration(2000);
fadeOut.setFillAfter(true);
fadeOut.setAnimationListener(new AnimationListener(){
@Override
public void onAnimationEnd(Animation animation) {
if(help!=null) {
//palce old help text back again
giftFinal.setText(help);
giftFinal.setTextColor(Color.BLACK);
giftFinal.setBackgroundColor(Color.WHITE);
giftFinal.setAlpha(alpha);
giftFinal.setVisibility(View.VISIBLE);
}
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationStart(Animation animation) {}
});
giftFinal.startAnimation(fadeOut);
这是因为您已将 setFillAfter 设置为 true。根据documentation,"If fillAfter is true, the transformation that this animation performed will persist when it is finished. Defaults to false if not set."所以去掉fadeOut.setFillAfter(true)
或者改成fadeOut.setFillAfter(false)
.
我想知道为什么在我的按钮 giftFinal 下面的代码中没有取回他的 alpha。执行后按钮文本不可见。甚至没有设置文本颜色或背景颜色:
final float alpha=giftFinal.getAlpha();
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setStartOffset(30000);
fadeOut.setDuration(2000);
fadeOut.setFillAfter(true);
fadeOut.setAnimationListener(new AnimationListener(){
@Override
public void onAnimationEnd(Animation animation) {
if(help!=null) {
//palce old help text back again
giftFinal.setText(help);
giftFinal.setTextColor(Color.BLACK);
giftFinal.setBackgroundColor(Color.WHITE);
giftFinal.setAlpha(alpha);
giftFinal.setVisibility(View.VISIBLE);
}
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationStart(Animation animation) {}
});
giftFinal.startAnimation(fadeOut);
这是因为您已将 setFillAfter 设置为 true。根据documentation,"If fillAfter is true, the transformation that this animation performed will persist when it is finished. Defaults to false if not set."所以去掉fadeOut.setFillAfter(true)
或者改成fadeOut.setFillAfter(false)
.