如何制作这样的圆形视图

时间:2016-04-07 19:46:13

标签: java android view geometry

如何制作这样的圆形视图?它略大于圆的四分之一

enter image description here

这是我的代码,但没有成功得到相同的结果: 对不起我的英语,我来自巴西

public class Circle extends View {
private Context context;

private final Paint paint;
private final RectF rectF;
private final Rect rect;

private int w = 200;
private int h = 200;

private final float roundPx = 100 ;

public Circle(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.BLUE);

    rect = new Rect(0, 0, w,h);
    rectF = new RectF(rect);

}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.drawARGB(0, 0, 0, 0);

    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

        canvas.drawRect(0, 0, w, h, paint);

        canvas.drawRect(w/2, h/2, w, h, paint);

}}

enter image description here

0 个答案:

没有答案