【问题标题】:How to get Animation from View如何从视图中获取动画
【发布时间】:2018-02-18 00:09:22
【问题描述】:

我在适配器的点击事件中为ProgressBar 设置了一个动画

ObjectAnimator animation = ObjectAnimator.ofInt(holder.progressbar, "progress", 0, 100);
animation.setDuration(PROGRESS_TIME);
animation.setInterpolator(new DecelerateInterpolator());
animation.addListener(new Animator.AnimatorListener() {

@Override
public void onAnimationStart(Animator animator) {
    Toast.makeText(context,"HELL_Start",Toast.LENGTH_SHORT).show();
}

@Override
public void onAnimationEnd(Animator animator) {
    //do something when the countdown is complete
    Toast.makeText(context,"HELL_OFF_END",Toast.LENGTH_SHORT).show();
}

@Override
public void onAnimationCancel(Animator animator) {
    Toast.makeText(context,"HELL_OFF_Cancel",Toast.LENGTH_SHORT).show();
}

@Override
public void onAnimationRepeat(Animator animator) { }
});

animation.start();

我正在尝试使用

ProgressBar 获取动画(当列表项值更改时)

AlphaAnimation animation = (AlphaAnimation)mProgressBar.getAnimation();

但它正在返回null

【问题讨论】:

  • 您的对象动画师独立于视图工作,因此您无法从视图中获取它。但是你为什么不直接引用你创建的动画呢?
  • @dominicoder 如何为每个列表项添加它,然后在单击时引用它

标签: android android-animation android-progressbar


【解决方案1】:

您可以将动画对象设置为关联视图的标签。

holder.progressbar.setTag(animation);

比以后检索它:

ObjectAnimator animator = (ObjectAnimator) holder.progressBar.getTag();
// Do something with animator

【讨论】:

  • 谢谢,它有效,不确定这种方法是否好,或者我应该为每个列表项添加处理程序
  • 为每个项目添加一个处理程序意味着一个动画会驱动所有项目,这可能不是你想要的。
  • 也许你错过了调用 getTag() 来获取 ObjectAnimator。
  • 哦,是的,我做到了——很奇怪。固定的。谢谢。
猜你喜欢
  • 1970-01-01
  • 2012-12-06
  • 1970-01-01
  • 2016-05-12
  • 1970-01-01
  • 2015-01-01
  • 2014-09-16
  • 1970-01-01
  • 2019-10-26
相关资源
最近更新 更多