效果 (How to Imeplement Vibration Effect In Andoid)"/>
Android中实现振动效果 (How to Imeplement Vibration Effect In Andoid)
实现振动效果,需要调用Android系统提供的Vibrator,Vibrator主要的API有:Ÿ vibrate(long milliseconds)振动指定的时间。
Ÿ vibrate(long[] pattern, int repeat)按照给定的模式振动。
Patterns指定振动模式,数组的每个整数是一个时间间隔,第一个整数指定等待多长时间开始振动,后面的参数依次重复指定振动持续的时间和振动间隔的时间。
Repeat指定patter数组中的一个索引值,从这个值开始不断重复振动模式,如果为-1则不重复振动。
Ÿ cancel()取消振动。
下面是不同振动效果的例子(来自参考资料[2]),这些代码需要在一个Context(如Activity, Service)中进行调用。注意默认情况下当屏幕暗掉时,振动也会停止,可以通过设置屏幕常亮来使振动持续。
1.1 振动指定的时间
更多推荐
Android中实现振动效果 (How to Imeplement Vibration Effect In Andoid)
发布评论