动图太极

package ss.jind.com.zhouoneweek.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;



public class TaiJinView extends View implements View.OnClickListener {
    private RotateAnimation rotateAnimation;
    private int width = 360;
    private int height = 360;
    private int padding = 5;
    private Paint mPaint;
    private RectF mRectf;


    private RectF blackHalfRect1;
    private RectF whiteHalfRect;

    public TaiJinView(Context context) {
        super(context);

    }

    public TaiJinView(Context context, AttributeSet attrs) {
        super(context, attrs,0);

    }

    public TaiJinView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }
    private void initPaint() {
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setStrokeWidth(5);
    }
    private void initAnim() {
        //以view的中心点为旋转参考点
        rotateAnimation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setRepeatCount(-1);
        rotateAnimation.setFillAfter(false);
    }



    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(width,height);
        mRectf = new RectF(0,0,width,width);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        initPaint();
        initAnim();
        setOnClickListener(this);
        
        drawCirCle(canvas);
        drawHalfCirCle(canvas);
        drawSmallCircle(canvas);
    }
    private void drawSmallCircle(Canvas canvas) {
        mPaint.setColor(Color.WHITE);
        mPaint.setStyle(Paint.Style.FILL);
        canvas.drawCircle(width/2,width/4,20,mPaint);

        mPaint.setColor(Color.BLACK);
        mPaint.setStyle(Paint.Style.FILL);
        canvas.drawCircle(width/2,width/4*3,20,mPaint);
    }




    private void drawCirCle(Canvas canvas) {
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setColor(Color.WHITE);
        canvas.drawArc(mRectf,270,180,true,mPaint);
        mPaint.setColor(Color.BLACK);
        canvas.drawArc(mRectf,270,-180,true,mPaint);
    }
    private void drawHalfCirCle(Canvas canvas) {
        //画上面黑色半圆
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setColor(Color.BLACK);
        blackHalfRect1 = new RectF(width/4,0,width/2+width/4,width/2);
        canvas.drawArc(blackHalfRect1,270,180,true,mPaint);


        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setColor(Color.WHITE);
        whiteHalfRect = new RectF(width/4,width/2,width/2+width/4,width);
        canvas.drawArc(whiteHalfRect,270,-180,true,mPaint);
    }



    @Override
    public void onClick(View v) {

        rotateAnimation.setDuration(1000);
        rotateAnimation.setInterpolator(new LinearInterpolator());//不停顿
        startAnimation(rotateAnimation);
    }
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值