代码之家  ›  专栏  ›  技术社区  ›  Rahul Matte

如何从视图中获取动画

  •  1
  • Rahul Matte  · 技术社区  · 9 年前

    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();
    

    进度条 通过使用

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

    但它正在回归 null

    1 回复  |  直到 9 年前
        1
  •  2
  •   dominicoder    7 年前

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

    holder.progressbar.setTag(animation);
    

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