我有一个活动,当启动时,在屏幕上显示一些辅导员视图(所有ImageButtons),表明应用程序应该如何使用(某些按钮的功能,滑动行为等)。淡出动画与这些视图中的每个视图相关联,这些视图在某个预定义的间隔之后触发。这与预期的一样。但是,如果用户以某种方式与活动交互,我希望这些标记能更早地消失。当这些动作被触发时,我取消动画并在coachmark视图上调用setVisibility(View.INVISIBLE);。但是,视图的可见性不会改变。我还尝试过其他技术--从父视图中移除视图并将alpha设置为0,这些方法都很好用,但改变视图可见性并不起作用。
设置coachmark的代码如下所示:
private void animateCoachmark(int id) {
AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
final View view = findViewById(id);
animation.setStartOffset(10000);
animation.setDuration(500);
animation.setAnimationListener(new AnimationListenerBase(null) {
@Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(View.INVISIBLE);
}
});
view.startAnimation(animation);
coachmarkViews.add(view);
}改变可见性的有问题的代码:
for (final View coachmarkView : coachmarkViews) {
Animation animation = coachmarkView.getAnimation();
if (animation != null) {
animation.cancel();
}
coachmarkView.setVisibility(View.INVISIBLE);
}发布于 2014-05-30 23:46:40
这个问题似乎是,只要动画与视图相关联,对可见性的更改就不会生效,即使动画已经取消。修改我的清理代码,首先将视图上的动画设置为null,这样视图就可以像预期的那样消失。
for (final View coachmarkView : coachmarkViews) {
Animation animation = coachmarkView.getAnimation();
if (animation != null) {
animation.cancel();
coachmarkView.setAnimation(null);
}
coachmarkView.setVisibility(View.INVISIBLE);
}https://stackoverflow.com/questions/23958481
复制相似问题