设为首页 加入收藏

TOP

Android--Vibrator实现手机震动效果
2014-11-24 08:27:20 来源: 作者: 【 】 浏览:0
Tags:Android--Vibrator 实现 手机 震动 效果

手机的震动功能相信大家都不会陌生,现在就让我们解读手机的震动。其实,要实现手机的震动并不难,只需要实现一个类,并调用其中的方法,设定相应的参数即可。


下面给出介绍:


这段文档来自Google SDK文档



Class that operates the vibrator on the device.


If your process exits, any vibration you started with will stop.


To obtain an instance of the system vibrator, call getSystemService(String) with VIBRATOR_SERVICE as argument.


我们通常实现的方法如下:


public abstract void vibrate (long[] pattern, int repeat)
Added in API level 1Vibrate with a given pattern.


Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds. The first value indicates the number of milliseconds to wait before turning the vibrator on. The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.


To cause the pattern to repeat, pass the index into the pattern array at which to start the repeat, or -1 to disable repeating.


This method requires the caller to hold the permission VIBRATE.


Parameters
pattern an array of longs of times for which to turn the vibrator on or off.
repeat the index into pattern at which to repeat, or -1 if you don't want to repeat.



下面给出一个具体的实例实现震动效果(需要在真机上运行)
1.布局文件的代码


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android--强大的Toast实现多种效果 下一篇Android游戏编程Manifest文件准备

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)
·MySQL 数据类型:从 (2025-12-26 18:20:03)
·Linux Shell脚本教程 (2025-12-26 17:51:10)
·Qt教程,Qt5编程入门 (2025-12-26 17:51:07)