Android中实现振动效果 (How to Imeplement Vibration Effect In Andoid)

编程入门 行业动态 更新时间:2024-10-25 05:12:33

Android中实现振动<a href=https://www.elefans.com/category/jswz/34/1770448.html style=效果 (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)

本文发布于:2024-02-17 15:16:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1694490.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:效果   Imeplement   Android   Andoid   Effect

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!