[android] 手机卫士输入框抖动和手机震动
来源:互联网 发布:网络批发干货平台 编辑:程序博客网 时间:2024/04/26 21:46
查看apiDemos,找到View/Animation/shake找到对应的动画代码,直接拷贝过来
当导入一个项目的时候,报R文件不存在,很多情况是xml文件出错了
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
et_phone.startAnimation(shake);
动画的xml文件shake.xml
android:interpolator="@anim/cycle_7"
interpolator是插入器,可以定义动画的速度等
调用Animation对象的setInterpolator()方法,设置插入器,参数:Interpolator对象
匿名实现Interpolator接口,重写getInterpolation()方法,设置中自定义动画速率,传入一个flaot x
输入框的震动效果
获取Vibrator对象,调用getSystemService()方法,参数:VIBRATOR_SERVICE
调用Vibrator对象的vibrate()方法,参数:毫秒
需要添加权限android.permission.VIBRATE
这个可以做一些振动器~
/** * 查询归属地 */ public void queryNumber(View v) { phone = et_phone.getText().toString().trim(); if (TextUtils.isEmpty(phone)) { //抖动动画 Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake); et_phone.startAnimation(shake); //手机震动 vibrator.vibrate(2000); Toast.makeText(this, "请输入手机号码", 0).show(); return; } String result = NumberQueryAddressUtil.queryAddress(phone); tv_address.setText(result); }
shake.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXDelta="0" android:interpolator="@anim/cycle_7" android:toXDelta="10" />
cycle_7.xml
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />
转自:http://www.cnblogs.com/taoshihan/p/5425895.html
阅读全文
0 0
- [android] 手机卫士输入框抖动和手机震动
- 手机输入框抖动效果 和 震动效果
- Android手机震动抖动效果的实现
- 控件抖动配合手机震动
- Android-抖动动画、手机震动和设置成前台进程的实现
- EditText左右抖动,内容变化监听和手机震动
- android项目-手机卫士
- Android实战--手机卫士
- Android手机卫士
- Android手机卫士总结
- Android 手机卫士开篇
- android 学习 手机震动
- Android 手机震动
- Android 调用手机震动
- Android 手机震动节奏
- android--手机震动--Vibrator
- Android 手机震动控制
- Android学习 - 手机震动
- Centos 7 批量重命名文件名
- videoview全屏播放
- Fragment使用时候的Import问题import android.support.v4.app.Fragment
- erlang的case和if
- Appium 截图方法
- [android] 手机卫士输入框抖动和手机震动
- springmvc
- 使用一般处理程序.ashx
- PostgreSQL 30天 培训视频(SQL基础,备份恢复,HA,服务端编程,大数据,内核,应用案例)
- Javascript 中的神器——Promise
- ubuntu下sge下载
- 串口TXD和RXD的线序导致不能通信的问题
- Android SurfaceFlinger 学习之路(二)----SurfaceFlinger概述
- 使用Maven构建Spring项目“HelloWorld”