我正在尝试画一个圆形的drawable,它由不同颜色的水平分割组成。 但是我从drawable剪切的圆形路径创建了一个圆周断开的圆圈。
以下是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模式,但它们没有按照给定的方式工作。