设置背景Drawable时的动画

时间:2016-02-20 07:02:27

标签: android android-layout android-studio android-animation

我有一个textView,显示一些名称,比如说( Harley ),然后点击一个按钮,我将 Harley 的背景设置为可绘制的形状,它也是它的颜色。 一切正常。

我想在设置背景时应用动画,它应该像设置背景时一样放大。

我尝试在textView上使用缩放动画,但没有运气。

任何帮助或建议将不胜感激。

我已经解决了这个问题,在drawable设置为textView之后应用 ScaleAnimation

ScaleAnimation mScaleAnimation = new ScaleAnimation(0.0f, 1.0f,
                0.0f, 1.0f,
                Animation.RELATIVE_TO_PARENT, 0.5f,
                Animation.RELATIVE_TO_PARENT, 0.5f);
        mScaleAnimation.setDuration(500);

 viewRoboto.clearAnimation();
 viewRoboto.setAnimation(mScaleAnimation);

2 个答案:

答案 0 :(得分:3)

您可以使用TransitionDrawable in Android来实现此类功能。另请查看this answer.

答案 1 :(得分:1)

更好地利用Property Animation Api这对我有用

int colorFrom = getResources().getColor(R.color.red);
int colorTo = getResources().getColor(R.color.blue);
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(250); // milliseconds
colorAnimation.addUpdateListener(new AnimatorUpdateListener() {

    @Override
    public void onAnimationUpdate(ValueAnimator animator) {
        textView.setBackgroundColor((int) animator.getAnimatedValue());
    }

});
colorAnimation.start();
相关问题