自定义View绘制简单的圆环的实现
package com.loaderman.mywave; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.view.View; /** * * 绘制简单圆环 */ public class SimpleRing extends View { private Paint paint; public SimpleRing(Context context) { this(context, null); } public SimpleRing(Context context, AttributeSet attrs) { this(context, attrs, -1); } public SimpleRing(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Paint.Style.STROKE);//空心 paint.setStrokeWidth(10);//设置圆环宽度 paint.setAntiAlias(true);//去掉锯齿 } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //绘制圆环: 参1,2: 圆心坐标; 参3:半径 canvas.drawCircle(getWidth() / 2, getHeight() / 2, 100, paint); } }
效果图:
最后,关注【码上加油站】微信公众号后,有疑惑有问题想加油的小伙伴可以码上加入社群,让我们一起码上加油吧!!!