浅析Android手机卫士之抖动输入框和手机震动
查看apiDemos,找到View/Animation/shake找到对应的动画代码,直接拷贝过来
当导入一个项目的时候,报R文件不存在,很多情况是xml文件出错了
Animationshake=AnimationUtils.loadAnimation(this,R.anim.shake);
et_phone.startAnimation(shake);
动画的xml文件shake.xml
android:interpolator="@anim/cycle_7"
interpolator是插入器,可以定义动画的速度等
调用Animation对象的setInterpolator()方法,设置插入器,参数:Interpolator对象
匿名实现Interpolator接口,重写getInterpolation()方法,设置中自定义动画速率,传入一个flaotx
输入框的震动效果
获取Vibrator对象,调用getSystemService()方法,参数:VIBRATOR_SERVICE
调用Vibrator对象的vibrate()方法,参数:毫秒
需要添加权限android.permission.VIBRATE
这个可以做一些振动器~
/**
*查询归属地
*/
publicvoidqueryNumber(Viewv){
phone=et_phone.getText().toString().trim();
if(TextUtils.isEmpty(phone)){
//抖动动画
Animationshake=AnimationUtils.loadAnimation(this,R.anim.shake);
et_phone.startAnimation(shake);
//手机震动
vibrator.vibrate(2000);
Toast.makeText(this,"请输入手机号码",0).show();
return;
}
Stringresult=NumberQueryAddressUtil.queryAddress(phone);
tv_address.setText(result);
}
shake.xml
<translatexmlns: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
<cycleInterpolatorxmlns:android="http://schemas.android.com/apk/res/android"android:cycles="7"/>
以上所述是小编给大家介绍的Android手机卫士之输入框抖动和手机震动的相关内容,希望对大家有所帮助!
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下