阿达老师专业推荐动画

阿达老师专业推荐动画_第1张图片
testing.gif
package com.XXXX.XXXX;


/**
 * @ClassName GetCirclePointView
 * @Description TODO
 * @Author cjd
 * @Date 2019-09-19 10:51
 */

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.View;


public class AnimotionImage extends View {
//    private Paint mPaint;
    private int w, h;
    int angle = 0;
    Bitmap bitmap;

    public AnimotionImage(Context context) {
        super(context);
        init();
    }

    public AnimotionImage(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public AnimotionImage(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        this.w = w;
        this.h = h;
    }

    private void init() {

//        mPaint = new Paint();
//        mPaint.setStrokeWidth(5);
//        mPaint.setColor(Color.WHITE);
//        mPaint.setAntiAlias(true);
//        mPaint.setStyle(Paint.Style.STROKE);
        bitmap = BitmapFactory.decodeResource(getResources(), com.cnlaunch.batterytest.R.drawable.rotation_image);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //将圆点平移到View的中心,而不是默认的左上角
        canvas.translate(w / 2, h / 2);

        int radius = 20;

//        canvas.drawCircle(0, 0, radius, mPaint);


//        for(int i = 0;i<360;i+= 30){
        //计算小圆的圆心点(x,y)点在圆的边上
        int x = 0 + (int) (radius * Math.cos(angle * Math.PI / 180));
        int y = 0 + (int) (radius * Math.sin(angle * Math.PI / 180));
        angle += 5;

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.BLUE);
        paint.setAntiAlias(true);
//        canvas.drawCircle(x, y, 20, paint);
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        canvas.drawBitmap(bitmap, x - width / 2, y - height / 2, paint);
        mHandler.sendEmptyMessageDelayed(0, 10);


//        }
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            angle += 5;
            invalidate();

        }
    };
}

你可能感兴趣的:(阿达老师专业推荐动画)