I want to draw a Circle and cross over this by using Shape drawable in android just like
if anybody have idea how can it be achieved. Please help. I am not able to create Cross inside Circle.
Use this one code
class MyView extends View {
Paint paint1 = new Paint();
Paint paint2 = new Paint();
Paint paint3 = new Paint();
Paint paint4 = new Paint();
Paint paint5 = new Paint();
final RectF rect = new RectF();
int mRadius = 130;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// Example values
rect.set(getWidth() / 2 - mRadius, getHeight() / 2 - mRadius,
getWidth() / 2 + mRadius, getHeight() / 2 + mRadius);
paint1.setColor(Color.RED);
paint1.setStrokeWidth(16);
paint1.setAntiAlias(true);
paint1.setStrokeCap(Paint.Cap.BUTT);
paint1.setStyle(Paint.Style.STROKE);
paint2.setColor(Color.RED);
paint2.setStrokeWidth(mRadius / 2);
paint2.setAntiAlias(true);
paint2.setStrokeCap(Paint.Cap.BUTT);
paint2.setStyle(Paint.Style.STROKE);
paint3.setColor(Color.RED);
paint3.setStrokeWidth(16);
paint3.setAntiAlias(true);
paint3.setStrokeCap(Paint.Cap.BUTT);
paint3.setStyle(Paint.Style.STROKE);
canvas.drawArc(rect, 0, 3600, false, paint1);
canvas.drawLine(getWidth() / 2, getHeight() / 2, getWidth() / 2
- mRadius, getHeight() / 2 - mRadius, paint3);
canvas.drawLine(getWidth() / 2, getHeight() / 2, getWidth() / 2
+ mRadius, getHeight() / 2 - mRadius, paint3);
canvas.drawLine(getWidth() / 2, getHeight() / 2, getWidth() / 2
- mRadius, getHeight() / 2 + mRadius, paint3);
canvas.drawLine(getWidth() / 2, getHeight() / 2, getWidth() / 2
+ mRadius , getHeight() / 2 + mRadius , paint3);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.