Skip to content

Instantly share code, notes, and snippets.

@DastanIqbal
Last active May 24, 2017 03:41
Show Gist options
  • Save DastanIqbal/808f58131fdfb46ed8fa4b7f12ae5046 to your computer and use it in GitHub Desktop.
Save DastanIqbal/808f58131fdfb46ed8fa4b7f12ae5046 to your computer and use it in GitHub Desktop.
CircleView in Android
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 CircleView extends View {
private Paint mPaint;
private Paint mStrokePaint;
public CircleView(Context context, AttributeSet attrs) {
super(context, attrs);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mStrokePaint.setAntiAlias(true);
mStrokePaint.setStyle(Paint.Style.STROKE);
mStrokePaint.setStrokeWidth(2);
mStrokePaint.setColor(Color.BLACK);
mStrokePaint.setStrokeCap(Paint.Cap.BUTT);
}
public void setColor(String color) {
mPaint.setColor(Color.parseColor(color));
}
@Override
protected void onDraw(Canvas canvas) {
int width = getWidth();
int height = getHeight();
canvas.drawCircle(width / 2, height / 2, (width-10) / 2, mPaint);
canvas.drawCircle(width / 2, height / 2, (width-10) / 2, mStrokePaint);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment