首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从视图中获取动画

如何从视图中获取动画
EN

Stack Overflow用户
提问于 2017-09-09 04:25:34
回答 1查看 838关注 0票数 1

我在适配器中的单击事件中设置了ProgressBar动画

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-09 13:02:59

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

代码语言:javascript
复制
holder.progressbar.setTag(animation);

而不是稍后再检索:

代码语言:javascript
复制
ObjectAnimator animator = (ObjectAnimator) holder.progressBar.getTag();
// Do something with animator
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46127089

复制
相关文章

相似问题

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