在我的活动中,我有一个开始按钮,当点击它时它会淡出并最终消失setVisibility(View.GONE)
问题是设置GONE的可见性不会消失视图,它仍然可见。我有目的地将视图动画淡出为0.1(而不是0),即使在我调用setVisibility(View.GONE)
之后,我也可以在后台看到它。
淡出动画anim_fade_out.xml
是:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true" android:fillEnabled="true">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="200" />
</set>
该方法为showTimer()
:
private void showTimer() {
final LinearLayout startButtonArea = (LinearLayout)findViewById(R.id.startButtonArea);
Animation animFadeOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.anim_fade_out);
startButtonArea.startAnimation(animFadeOut);
animFadeOut.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
startButtonArea.setVisibility(View.GONE);
Log.d("Animation ended","startButtonArea SHOULD BE GONE BUT IT ISN'T");
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationStart(Animation animation) {}
});
}
重申一下,我知道动画的结束alpha是0.1(通常是0)但是我想确认视图真的是GONE
而不是。
答案 0 :(得分:7)
因为fillAfter
为真,动画会在调用onAnimationEnd
后设置属性。您可以将fillAfter
更改为false,或者像这样执行:
@Override
public void onAnimationEnd(Animation animation) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startButtonArea.setVisibility(View.GONE);
Log.d("Animation ended","startButtonArea SHOULD BE GONE BUT IT ISN'T");
}
}, 0);
}