本例为一密码输入框添加“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;">


更多相关文章

  1. Android(安卓)实现RippleEffect水波纹效果
  2. 开发技术前线 第六期
  3. android 水下气泡上升界面效果
  4. Android(安卓)UI控件之Gallery实现循环效果总结
  5. Android基于XMPP Smack Openfire下学习开发IM(一)实现用户注册、
  6. Android(安卓)开发笔记 动画效果 --Animation 动画专题研究(xml)
  7. Android的Activity滑动切换动画
  8. android Toast大全(五种)
  9. CSS 3模仿android 中的toast效果

随机推荐

  1. Android调用系统分享,资源未找到问题
  2. 关于Android音频、视频录制类MediaRecord
  3. 控件布局_LinearLayout
  4. android点滴
  5. Android的IPC机制Binder的详解汇总
  6. 开源终端Android(安卓)Terminal Emulator
  7. Android(安卓)requires compiler complia
  8. Freeline 一款 Android平台上的秒级编译
  9. Android.Documentation
  10. LinearLayout 内部控件居中