如何以编程方式实现抖动动画? [英] How to achieve shake animation programmatically?
本文介绍了如何以编程方式实现抖动动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Android中以编程方式实现抖动/摆动动画.有一个 AndroidViewAnimations 库,通过该库我们可以得到效果.但是我不想为此目的使用任何库,因为它会增加apk的大小.
How can I achieve shake/wobble animation in android programmatically. There is a AndroidViewAnimations library available through which we can get the effect. But I don't want to use any library for this purpose as it tends to increase the apk size.
AndroidViewAnimations 中用于摇动动画的代码如下:
The code present in the AndroidViewAnimations for shake animation is as follows:
public class ShakeAnimator extends BaseViewAnimator {
@Override
public void prepare(View target) {
getAnimatorAgent().playTogether(
ObjectAnimator.ofFloat(target, "translationX", 0, 25, -25, 25, -25,15, -15, 6, -6, 0)
);
}
}
annyone可以告诉我如何在没有任何库的情况下实现这一目标.
Can annyone tell me how can I achieve this without any libraries.
推荐答案
让我们说 mView
是要设置动画的视图:
let's say that mView
is the view you want to animate:
ObjectAnimator
.ofFloat(mView, "translationX", 0, 25, -25, 25, -25,15, -15, 6, -6, 0)
.setDuration(duration)
.start();
这篇关于如何以编程方式实现抖动动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文