<ImageView
android:id="@+id/tv_hunt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dp"
android:layout_marginLeft="20dp"
android:drawablePadding="5dp"
android:src="@anim/pull_to_refresh_animation"/>
<?xml version="1.0" encoding="utf-8" ?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false"
>
<item
android:drawable="@drawable/fresh1"
android:duration="150"/>
<item
android:drawable="@drawable/fresh2"
android:duration="100"/>
<item
android:drawable="@drawable/fresh3"
android:duration="100"/>
<item
android:drawable="@drawable/fresh4"
android:duration="100"/>
<item
android:drawable="@drawable/fresh5"
android:duration="100"/>
<item
android:drawable="@drawable/fresh6"
android:duration="100"/>
<item
android:drawable="@drawable/fresh7"
android:duration="100"/>
<item
android:drawable="@drawable/fresh8"
android:duration="100"/>
</animation-list>
private void onHunt() {
if (oldX == 0) oldX = mHunt.getX();
if (oldY == 0) oldY = mHunt.getY();
mHunt.setX(oldX);
mHunt.setY(oldY);
final AnimationDrawable drawable = (AnimationDrawable) mHunt.getDrawable();
if (drawable.isRunning())
drawable.stop();
//开始动画
drawable.start();
PropertyValuesHolder pvTX = PropertyValuesHolder.ofFloat("x", mHunt.getX(),
width / 2);
PropertyValuesHolder pvTY = PropertyValuesHolder.ofFloat("y", mHunt.getY(),
height / 2);
ObjectAnimator whxyBouncer = ObjectAnimator.ofPropertyValuesHolder(mHunt,
pvTX, pvTY).setDuration(3000);
whxyBouncer.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
drawable.stop();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
whxyBouncer.start();
}