Как сделать что бы изображение крутилось вокруг с своей оси без остановки?

code: #java
public class GraphicsView extends View {
    private Animation anim;
 
    private Bitmap jobs;
    private int jobsXOffset;
    private int jobsYOffset;
 
    public GraphicsView(Context context) {
        super(context);
 
        jobs = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        jobsXOffset = jobs.getWidth() / 2;
        jobsYOffset = jobs.getHeight() / 2;
    }
 
    private void createAnim(Canvas canvas) {
        anim = new RotateAnimation(0, 360, canvas.getWidth() / 2, canvas.getHeight() / 2);
        anim.setRepeatMode(Animation.REVERSE);
        anim.setRepeatCount(Animation.INFINITE);
        anim.setDuration(10000L);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
 
        startAnimation(anim);
    }
 
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
 
        // creates the animation the first time
        if (anim == null) {
            createAnim(canvas);
        }
 
        int centerX = canvas.getWidth() / 2;
        int centerY = canvas.getHeight() / 2;
 
        canvas.drawBitmap(jobs, centerX - jobsXOffset, centerY - jobsYOffset, null);
    }
}

автор: dajver

Поделиться:

Похожие статьи: