springAnimationY.setStartVelocity(velocityY); springAnimationY.setStartValue(mParams.y); springAnimationY.setSpring(springY);
springAnimationX.setStartVelocity(mVelocityTracker.getXVelocity()); springAnimationX.setStartValue(mParams.x); springAnimationX.setSpring(springX);
spring.setStartVelocity(velocity).animateToFinalPosition(restrictionRect.left + horizontalDiff); } else if (afterRect.right < restrictionRect.right) { cancel(); spring.setStartVelocity(velocity).animateToFinalPosition(restrictionRect.right - target.getWidth() - horizontalDiff);
spring.setStartVelocity(velocity).animateToFinalPosition(restrictionRect.top + verticalDiff); } else if (afterRect.bottom < restrictionRect.bottom) { cancel(); spring.setStartVelocity(velocity).animateToFinalPosition(restrictionRect.bottom - target.getHeight() - verticalDiff);
float velocity = vt.getYVelocity(); anim.getSpring().setDampingRatio(mDampingRatio).setStiffness(mStiffness); anim.setStartVelocity(velocity).start(); vt.recycle();
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: // Create a spring animation along the view's Y position. // Let resting position be at the view's current Y position. final SpringAnimation anim = new SpringAnimation(this, (FloatPropertyCompat) DynamicAnimation.Y, this.getY()) .setStartVelocity(10000); // In pixels per second. // Low stiffness makes the spring bouncy. anim.getSpring().setStiffness(STIFFNESS_LOW); anim.start(); break; default: // Do nothing. } return super.onTouchEvent(event); } }
@Override public void onClick(View view) { final SpringAnimation springAnimation = new SpringAnimation(img, DynamicAnimation.X); final SpringForce springForce = new SpringForce(); springForce.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY); springForce.setStiffness(SpringForce.STIFFNESS_VERY_LOW); springForce.setFinalPosition(img.getX()); springAnimation.setSpring(springForce); springAnimation.setStartVelocity(2000); springAnimation.start(); } });
@Override public void onClick(View view) { SpringAnimation springAnimation = new SpringAnimation(img, DynamicAnimation.X); SpringForce springForce = new SpringForce(); springForce.setFinalPosition(img.getX()); springForce.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY); springForce.setStiffness(SpringForce.STIFFNESS_LOW); springAnimation.setSpring(springForce); springAnimation.setStartVelocity(2000); springAnimation.start(); img.setImageResource(R.drawable.ic_sentiment_very_satisfied_black_56dp); springAnimation.addEndListener(new DynamicAnimation.OnAnimationEndListener() { @Override public void onAnimationEnd(DynamicAnimation animation, boolean canceled, float value, float velocity) { img.setImageResource(R.drawable.ic_sentiment_neutral_black_56dp); } }); } });
@Override public void onClick(View view) { FloatPropertyCompat<View> scale = new FloatPropertyCompat<View>("scale") { @Override public float getValue(View view) { return view.getScaleX(); } @Override public void setValue(View view, float value) { view.setScaleX(value); view.setScaleY(value); } }; SpringAnimation stretchAnimation = new SpringAnimation(img, scale); stretchAnimation.setMinimumVisibleChange( DynamicAnimation.MIN_VISIBLE_CHANGE_SCALE); SpringForce force = new SpringForce(1); force.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY) .setStiffness(SpringForce.STIFFNESS_VERY_LOW); stretchAnimation.setSpring(force) .setStartVelocity(100); stretchAnimation.start(); } });