三种抖动效果
1. 左右抖动
2. 上下抖动
核心代码:
res/anim/cycle.xml
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="20" />
res/anim/shage_x.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="10"
android:duration="1000"
android:interpolator="@anim/cycle" />
res/anim/shage_y.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>
3. 仿苹果长按时的抖动
res/anim/anim.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="180"
android:fromDegrees="-2"
android:pivotX="100%"
android:pivotY="100%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toDegrees="2" />
代码中使用方法:
Animation shake = AnimationUtils.loadAnimation(
ShakeDemoActivity.this, R.anim.anim);
shake.reset();
shake.setFillAfter(true);
imageview.startAnimation(shake);
源码下载地址:
http://download.youkuaiyun.com/detail/liangguo03/4219580