package com.example.a03_gossip.gossipview; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View; /** * Created by yujie on 2017/11/30. */ public class DrawView extends View{ public DrawView(Context context) { super(context); } public DrawView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public DrawView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setStrokeWidth(5); paint.setStyle(Paint.Style.FILL); RectF leftRectF = new RectF(100, 100, 500, 500); paint.setColor(Color.WHITE); canvas.drawArc(leftRectF, 90, 180, false, paint); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.BLACK); canvas.drawArc(leftRectF, 90, 180, false, paint); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.FILL_AND_STROKE); RectF rightRectF = new RectF(100, 100, 500, 500); canvas.drawArc(rightRectF, -90, 180, false, paint); RectF upRectF = new RectF(200, 100, 400, 300); canvas.drawArc(upRectF, 90, 180, false, paint); paint.setColor(Color.WHITE); RectF downRectF = new RectF(200, 300, 400, 500); canvas.drawArc(downRectF, -90, 180, false, paint); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); canvas.drawArc(downRectF, -90, 180, false, paint); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); canvas.drawCircle(300, 200, 20, paint); paint.setColor(Color.BLACK); canvas.drawCircle(300, 400, 20, paint); } }
自定义View画八卦图
最新推荐文章于 2021-05-27 10:29:57 发布