i don't understand why isnt my canvas playing animation

37 Views Asked by At

i've asked bard(google ai) it keeps giving me these codes but it dosent do anything the square is frozen.im trying it on wallpaperservice canvas

i want to know how can i (modify/animate) items of canvas that i've already drawn

    Rect rectangle = new Rect(0, 0, 100, 100);
    Paint paint = new Paint();
    paint.setColor(Color.RED);
    canvas.drawRect(rectangle, paint);
    ObjectAnimator animator = ObjectAnimator.ofFloat(rectangle, "left", 0f, 500f);
    animator.setDuration(2000);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.addListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
    animator.start();
    }
    });
    
    animator.start();
0

There are 0 best solutions below