android - 在 Animated Vector Drawable 中为 "fillColor"属性设置动画

标签 android animation android-vectordrawable

在我的应用程序中,我使用箭头作为可绘制对象,我想为此设置 fillColor 属性的动画。我遇到了修改 pathData、transateY/X、旋转等属性的 AnimatedVectorDrawable 示例,如何为 fillColor 属性设置动画,以便我的箭头定期更改颜色?

最佳答案

函数 animate() 没有直接改变 fillColor 的方法,但你可以做一个小技巧。在接下来的代码中,我将向您展示如何使用函数 animate() 来模拟 fillColor 的变化,使用函数 animate 两次:

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

使用上面的代码,你可以在动画中改变一些drawable的属性,我的意思是,接下来的过程是: 1 - 动画使可绘制对象消失(alpha 0) 2 - 你改变你想要的属性(property) 3 - 动画使 drawable 再次出现(alpha 1)

如果您在 Timer 中使用此代码,您可以使可绘制对象定期更改颜色。

关于android - 在 Animated Vector Drawable 中为 "fillColor"属性设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38629456/

相关文章:

android - Appcompat 主题未应用于所有小部件

java - Tabhost 中没有动画/选择

css - 嵌套的伪元素::之前&::不使用@keyframes 动画之后

javascript - 既然我添加了计数器变量和间隔,为什么我的动画无法正常工作?

android - ImageView 上的 Vectordrawable 模糊位图

android - 如果在 Android Studio 中突出显示了至少一个 subview ,则突出显示可扩展 ListView 的标题 View

c# - 如何在 android/iOS 移动测试中截取屏幕截图 - C#?

android - VectorDrawableCompat.create 无法在旧设备上从 vector.xml 创建图像

android - 自定义 View 上的可绘制标签向量无效

android - 为什么旁遮普语(印度语)在某些智能设备上显示为方框?