首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >View.setVisibility(View.INVISIBLE)不适用于动画视图

View.setVisibility(View.INVISIBLE)不适用于动画视图
EN

Stack Overflow用户
提问于 2014-05-30 23:46:40
回答 1查看 2.1K关注 0票数 4

我有一个活动,当启动时,在屏幕上显示一些辅导员视图(所有ImageButtons),表明应用程序应该如何使用(某些按钮的功能,滑动行为等)。淡出动画与这些视图中的每个视图相关联,这些视图在某个预定义的间隔之后触发。这与预期的一样。但是,如果用户以某种方式与活动交互,我希望这些标记能更早地消失。当这些动作被触发时,我取消动画并在coachmark视图上调用setVisibility(View.INVISIBLE);。但是,视图的可见性不会改变。我还尝试过其他技术--从父视图中移除视图并将alpha设置为0,这些方法都很好用,但改变视图可见性并不起作用。

设置coachmark的代码如下所示:

代码语言:javascript
复制
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);
  }

改变可见性的有问题的代码:

代码语言:javascript
复制
for (final View coachmarkView : coachmarkViews) {
  Animation animation = coachmarkView.getAnimation();
  if (animation != null) {
    animation.cancel();
  }
  coachmarkView.setVisibility(View.INVISIBLE);
}
EN

回答 1

Stack Overflow用户

发布于 2014-05-30 23:46:40

这个问题似乎是,只要动画与视图相关联,对可见性的更改就不会生效,即使动画已经取消。修改我的清理代码,首先将视图上的动画设置为null,这样视图就可以像预期的那样消失。

代码语言:javascript
复制
for (final View coachmarkView : coachmarkViews) {
  Animation animation = coachmarkView.getAnimation();
  if (animation != null) {
    animation.cancel();
    coachmarkView.setAnimation(null);
  }
  coachmarkView.setVisibility(View.INVISIBLE);
}
票数 15
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23958481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档