画圆绕中心转动

1.先创建自定义view extends ImageView
private Timer timer=new Timer();
ObjectAnimator anim;
private Handler handler=new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message message) {
anim.start();
return false;
}
});
public Glide(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
int cirt=50;
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);
canvas.drawCircle(400,400,cirt,paint);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
switch (action){
case MotionEvent.ACTION_DOWN:
anim = ObjectAnimator.ofFloat(this, “rotation”, 0, 360);
anim.setDuration(5000);
anim.start();

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (!anim .isStarted()){
                    handler.sendEmptyMessage(1);
                }
            }
        },0,100);
        break;
}
return true;

}

2.在主类布局
android:layout_width=“match_parent”
android:layout_height=“match_parent” />

你可能感兴趣的:(andrio)