2016-07-28 105 views
2

在我的应用程序中,我使用箭头作为drawable,为此我想为fillColor属性设置动画效果。我遇到AnimatedVectorDrawable示例,它修改了诸如pathData,transateY/X,rotation等属性,我如何为fillColor属性设置动画,以便我的箭头定期更改颜色?在动画矢量中绘制“fillColor”属性可绘制

+0

你有没有具体的问题,使这项工作?在新的SO文档中有一个fillColor AnimatedVectorDrawable的基本示例:http://stackoverflow.com/documentation/android/1627/vectordrawable-and-animatedvectordrawable/5267/basic-animatedvectordrawable#t=201607281801296008494 –

回答

0

函数animate()没有获得直接更改fillColor的方法,但您可以执行一个小问题。在接下来的代码中,我向您展示如何使用功能动画()使用功能动画两次模拟填充颜色的变化:

drawableView.animate() 
    .alpha(0.0f) 
    .setDuration(100) 
    .setListener(new AnimatorListenerAdapter() { 
    @Override 
    public void onAnimationEnd(Animator animation) { 
     super.onAnimationEnd(animation); 
     /* 
     In this point you can change de color of drawable, 
     the color or property that you want to change (title, color, size...) 
     */ 
     drawableView.animate() 
      .alpha(1.0f) 
      .setDuration(100) 
      .setListener(new AnimatorListenerAdapter() { 
       @Override 
       public void onAnimationEnd(Animator animation) { 
        super.onAnimationEnd(animation); 
       } 
      }); 
    } 
}); 

使用上面的代码,你可以改变绘制的一些属性在动画里面,我的意思是,该proccess将是下一个: 1 - 动画做提拉消失(字母O) 2 - 改变属性你想 3 - 动画做提拉再次出现(阿尔法1)

如果您在Timer里面使用这个代码,你可以做到绘制周期性地改变颜色。