油漆一次只允许一种颜色.
mCanvas.drawColor(mBackgroundColor, PorterDuff.Mode.CLEAR);
mCanvas.setDrawFilter(mPaintFlagsDrawFilter);
mFillPaint.setStyle(Paint.Style.FILL);
mFillPaint.setColor(Color.RED);
mStrokePaint.setStyle(Paint.Style.STROKE);
mStrokePaint.setColor(Color.BLUE);
mStrokePaint.setStrokeWidth(2);
mStrokePaint.setStrokeCap(Paint.Cap.ROUND);
mRectF.set(0, 0, mWidth, mHeight);
mCanvas.drawRoundRect(mRectF, 10, 10, mFillPaint);
mCanvas.drawRoundRect(mRectF, 10, 10, mStrokePaint);
如果您发现圆角矩形看起来不正确,则可能会在视图的边界处剪切.调整RectF以允许StrokeWidth的一半:
mRectF.set(1, 1, mWidth - 1, mHeight - 1);