【发布时间】:2014-01-30 11:39:50
【问题描述】:
在我的活动中,我有一个开始按钮,当点击它时,它应该会淡出并最终消失 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 而不是。
【问题讨论】:
-
尝试使用 INVISIBLE 代替消失
标签: android