Anroid自定义View-绘制圆环
Posted yayun0516
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Anroid自定义View-绘制圆环相关的知识,希望对你有一定的参考价值。
自定义View代码如下:
public class CircleProgress extends View private Paint mPaint; private int mWidth; private int mHeight; private static final int RING_WIDTH =80; public CircleProgress(Context context) super(context); initPaint(); private void initPaint() mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(Color.YELLOW); public CircleProgress(Context context, AttributeSet attrs) super(context, attrs); initPaint(); @Override protected void onDraw(Canvas canvas) super.onDraw(canvas); mWidth = getWidth(); mHeight = getHeight(); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(RING_WIDTH); canvas.drawCircle(mWidth / 2, mHeight / 2, 100, mPaint);
MainActivity.java代码如下:
public class MainActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(new CircleProgress(this));
运行实例如下:
以上是关于Anroid自定义View-绘制圆环的主要内容,如果未能解决你的问题,请参考以下文章