1 移动到底部上下抖动
ObjectAnimator animatorX = ObjectAnimator.ofFloat(holder.itemView,"translationX",0,0);
ObjectAnimator animatorY = ObjectAnimator.ofFloat(holder.itemView,"translationY",0,10,15,10,0);
AnimatorSet set =new AnimatorSet();
set.setDuration(1000);
set.setInterpolator(new SpringScaleInterpolator(0.4f));
set.playTogether(animatorX,animatorY);
set.start();
2,移动左边或者右边边缘,左右抖动
ObjectAnimator animatorX = ObjectAnimator.ofFloat(holder.itemView,"translationX",0,10,15,10,0);
ObjectAnimator animatorY = ObjectAnimator.ofFloat(holder.itemView,"translationY",0,0);
AnimatorSet set =new AnimatorSet();
set.setDuration(1000);
set.setInterpolator(new SpringScaleInterpolator(0.4f));
set.playTogether(animatorX,animatorY);
set.start();
public class SpringScaleInterpolator implements Interpolator {
//弹性因数
private float factor;
public SpringScaleInterpolator(float factor) {
this.factor = factor;
}
@Override
public float getInterpolation(float input) {
return (float) (Math.pow(2, -10 * input) * Math.sin((input - factor / 4) * (2 * Math.PI) / factor) + 1);
}
}