在Android上对可绘制对象的颜色进行动画处理

时间:2019-06-19 06:45:22

标签: android android-animation drawable

我对Android上的动画知之甚少。到目前为止,我唯一使用的东西是这样的:

Animation anim = new ScaleAnimation(0, 1, 1, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1);
anim.setAnimationListener(new Animation.AnimationListener(){
    @Override
    public void onAnimationStart(Animation arg0) {
        mAnswerFeedback.setVisibility(View.VISIBLE);
    }
    @Override
    public void onAnimationRepeat(Animation arg0) {
    }
    @Override
    public void onAnimationEnd(Animation arg0) {
        mAnswerFeedback.setVisibility(View.INVISIBLE);
    }
    });
anim.setDuration(500);
myView.setBackgroundColor(ContextCompat.getColor(this, R.color.material_red_500));
myView.startAnimation(anim);

但是现在我要为可绘制对象的颜色设置动画,特别是边框项目的颜色。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/border">
        <shape android:shape="rectangle">
            <padding android:bottom="2dp"
                     android:left="2dp"
                     android:right="2dp"
                     android:top="2dp" />
            <corners android:radius="12dp" />
            <solid android:color="#ffffff" />
        </shape>
    </item>
    <item android:id="@android:id/background">
        <shape android:shape="rectangle">
            <corners android:radius="10dp" />
            <solid android:color="#e0e0e0" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape android:shape="rectangle">
                <corners android:radius="10dp" />
                <solid android:color="#b3e5fc" />
            </shape>
        </clip>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape android:shape="rectangle">
                <corners android:radius="10dp" />
                <solid android:color="#7ed9f0" />
            </shape>
        </clip>
    </item>
</layer-list>

是否可以像上面的示例一样对颜色变化进行动画处理(从中间开始,扩展到左侧和右侧)?

0 个答案:

没有答案