android 晃动监听,Android 摇晃动画代码实现技巧

有两种效果,下边进行详细介绍:

效果一:以自身x轴中轴为中心,左右以20°晃动

217443cb70d8

c7a583d2-857d-4c2c-bf95-9da5bd53f294.gif

/**

* 晃动动画

*

* 那么CycleInterpolator是干嘛用的??

* Api demo里有它的用法,是个摇头效果!

*

* @param counts 1秒钟晃动多少下

* @return Animation

*/

public static Animation shakeAnimation(int counts) {

Animation rotateAnimation = new RotateAnimation(0, 20, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

rotateAnimation.setInterpolator(new CycleInterpolator(counts));

rotateAnimation.setRepeatCount(-1);

rotateAnimation.setDuration(3000);

return rotateAnimation;

}

效果二:以自身x轴中轴为中心,左右平移

217443cb70d8

a3e004e1-769e-440c-ba84-a544d05434c5.gif

/**

* 晃动动画

*

* 那么CycleInterpolator是干嘛用的??

* Api demo里有它的用法,是个摇头效果!

*

* @param counts 1秒钟晃动多少下

* @return Animation

*/

public static Animation shakeAnimation(int counts) {

Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);

translateAnimation.setInterpolator(new CycleInterpolator(counts));

translateAnimation.setRepeatCount(100000);

translateAnimation.setDuration(1000);

return translateAnimation;

}

调用方式:

imageView.setAnimation(shakeAnimation(6));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值