我想绘制一个圆形并通过在Android中使用Shape drawable来交叉,就像
一样如果有人知道如何实现。请帮忙。我无法在Circle内创建Cross。
答案 0 :(得分:2)
使用这一个代码
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);
}
}