<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);">在这里我以一个图片作为例子,实现上下抖动和左右晃动的特效,用得到的小伙伴可以借鉴~</span>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);">在这里我以一个图片作为例子,实现上下抖动和左右晃动的特效,用得到的小伙伴可以借鉴~</span>
cycle.xml
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="9" />//晃动频率
上下抖动布局
可以写在anim文件夹中!
shake_y.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2500"
android:fromYDelta="0"
android:interpolator="@anim/cycle"
android:toYDelta="10" >
</translate>
左右抖动布局
shake_x.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromYDelta="0"
android:interpolator="@anim/cycle"
android:toYDelta="10" >
</translate>
代码调用:
//实例化一个图片
ImageView location=new ImageView(context);
//开启动画
Animation shakeAnim = AnimationUtils.loadAnimation(context,
R.anim.shake_y);
location.startAnimation(shakeAnim);