Android(安卓)ApiDemos示例解析(98):Views->Animation->Shake
16lz
2021-01-26
本例为一密码输入框添加“Shake” 动画效果,模拟密码输入错误后左右摆动文本框以提示用户密码不正确。
代码如下:
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);findViewById(R.id.pw).startAnimation(shake);
Shake效果是通过 translate 平移Animation 设置 cycleInterpolator 周期循环运动来实现的。
anim 的shake.xml
<translate xmlns:android=”http://schemas.android.com/apk/res/android” android:fromXDelta=”0″ android:toXDelta=”10″ android:duration=”1000″ android:interpolator=”@anim/cycle_7″ />
而anim/cycle_7 定义如下:
<cycleInterpolator xmlns:android=”http://schemas.android.com/apk/res/android” android:cycles=”7″ />
文本框左右摆动7此产生摆动效果。
Animation->Shake_第1张图片" src="https://img.it610.com/image/info5/ee0cd9736688463baffe6a086575a55e.jpg" width="650" height="466" style="border:1px solid black;">
更多相关文章
- Android(安卓)实现RippleEffect水波纹效果
- 开发技术前线 第六期
- android 水下气泡上升界面效果
- Android(安卓)UI控件之Gallery实现循环效果总结
- Android基于XMPP Smack Openfire下学习开发IM(一)实现用户注册、
- Android(安卓)开发笔记 动画效果 --Animation 动画专题研究(xml)
- Android的Activity滑动切换动画
- android Toast大全(五种)
- CSS 3模仿android 中的toast效果