Android - 需要ondraw()示例的帮助

时间:2013-09-02 06:54:59

标签: java android

我使用下面的代码绘制视图

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

        paint.setStyle(Style.STROKE);
        paint.setAntiAlias(true);
        paint.setColor(BACKGROUND_COLOR);

        final RectF rectl = new RectF(0,0,2* padding,getHeight());
        final RectF rectr = new RectF(getWidth()-(2* padding),0,getWidth(),getHeight());

        canvas.drawLine(padding, 0, getWidth()-padding, 0, paint);
        canvas.drawLine(padding,getHeight()-1, getWidth()-padding, getHeight()-1, paint);
        canvas.drawArc(rectl, 90, 180, true, paint);
        canvas.drawArc(rectr, 270, 180, true, paint);
    }

输出如下

enter image description here

但我希望,需要删除drawArc底线,如下所示,

enter image description here

如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

将drawArc的第三个参数设置为false。

useCenter意味着弧的中心也应该连接到两端,半圆和D之间的差异。