0

我正在尝试绘制一个由不同颜色的水平分区组成的圆形可绘制对象。但是我从可绘制对象中剪下的圆形路径会创建一个圆周断开的圆圈。可绘制的

这是来自 Drawable 的 onDraw() 的片段

@Override
public void draw(@NonNull Canvas canvas) {

    // get drawable dimensions
    Rect bounds = getBounds();

    int width = bounds.right - bounds.left;
    int height = bounds.bottom - bounds.top;

    mPath.reset();
    mPath.addCircle(width/2, height/2, width/2, Path.Direction.CW);
    canvas.clipPath(mPath);

    int barHeight = height / themeColors.length;
    mRectF.left = 0;
    mRectF.top = 0;
    mRectF.right = width;
    mRectF.bottom = height;
    //Draw Rect. consisting of multiple rects acc. to height
    for (int i = 0; i < themeColors.length; i++) {
        mPaint.setColor(themeColors[i]);

        canvas.drawRect(0, i*barHeight, width, (i+1)*barHeight , mPaint);
    }

    //Draw stroke border
    if(mStrokeWidth!=0)
        canvas.drawCircle(width/2, height/2, width/2, mStrokePaint);

}

我如何着手开发可绘制对象以使边缘平滑?这可以用 xml drawable 来完成吗?

编辑:我尝试使用带有绘画的 PorterDuff 模式,但它们没有按给定的方式工作。

4

0 回答 0