int width=360; private Paint paint; private RectF rectf; public TaijiTu(Context context) { super(context); init(); } public TaijiTu(Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } public TaijiTu(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); setMeasuredDimension(360,360); rectf = new RectF(0,0,360,360); } private void init() { paint = new Paint(); paint.setAntiAlias(true); paint.setStrokeWidth(5); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); huaYuan(canvas); } private void huaYuan(Canvas canvas) { paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); canvas.drawArc(rectf,270,180,true,paint); paint.setColor(Color.BLACK); canvas.drawArc(rectf,270,-180,true,paint); drawHalfCirCle(canvas); } private void drawHalfCirCle(Canvas canvas) { //畫上面黑色半圓 paint.setStyle(Paint.Style.FILL); paint.setColor(Color.BLACK); RectF blackHalfRect = new RectF(width/4,0,width/2+width/4,width/2); canvas.drawArc(blackHalfRect,270,180,true,paint); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); RectF whiteHalfRect = new RectF(width/4,width/2,width/2+width/4,width); canvas.drawArc(whiteHalfRect,270,-180,true,paint); getxiao(canvas); } private void getxiao(Canvas canvas) { paint.setStyle(Paint.Style.FILL); paint.setColor(Color.BLACK); canvas.drawCircle(width/2,width/4*3,20,paint); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); canvas.drawCircle(width/2,width/4,20,paint); }
Canvas畫太極圖
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.