How to translate animation on an image diagonally?

I want to animate the image diagonally as shown below. I tried to translate the animation, but I can do it either parallel to the X axis or parallel to the Y axis.

But I could not understand how to do it diagonally. And I'm also not sure that this can be done by translating an animation or some other animation. So please suggest me how I can do this, or if someone can give me a useful link, then I will also be informed.

enter image description here

+4
source share
2 answers

One way is to use AnimatorSetto play more ObjectAnimator.

private void animateDiagonalPan(View v) {
    AnimatorSet animSetXY = new AnimatorSet();

    ObjectAnimator y = ObjectAnimator.ofFloat(v,
                "translationY",v.getY(), targetY);

    ObjectAnimator x = ObjectAnimator.ofFloat(v,
                "translationX", v.getX(), targetX);

    animSetXY.playTogether(x, y);
    animSetXY.setInterpolator(new LinearInterpolator(1f));
    animSetXY.setDuration(300);
    animSetXY.start();
}

View Property, X Y:

final Property<YourView, Float> transProperty = new Property<YourView, Float>(
        float.class, "translation") {
    @Override
    public Float get(YourView) {
        return object.getTranslation();
    }

    @Override
    public void set(YourView, Float value) {
        object.translate(value);
    }
};

private void translate(float value){
       setTranslationX(value);
       setTranslationY(value);
}

:

private void animateDiagonalPan(View v) {

    ObjectAnimator xy = ObjectAnimator.ofFloat(v,
                transProperty, targetValue);

    xy.setInterpolator(new LinearInterpolator(1f));
    xy.setDuration(300);
    xy.start();
}
+14

ObjectAnimator.

ObjectAnimator centerChangeAnim = ObjectAnimator.ofObject(this, "centerpoint", new PointEvaluator(), fromPoint, toPoint);
centerChangeAnim.start()

.

public void setCenterpoint(Point centerPoint) {
    this.circleCenter = centerPoint;
  }

, X Y.

public class PointEvaluator implements TypeEvaluator<Point> {
    @Override
    public Point evaluate(float t, Point startPoint, Point endPoint) {
        int x = (int) (startPoint.x + t * (endPoint.x - startPoint.x));
        int y = (int) (startPoint.y + t * (endPoint.y - startPoint.y));
        return new Point(x,y);
    }
}

!

0

Source: https://habr.com/ru/post/1540190/


All Articles