2015-10-17 74 views
0

与Android 6启动drawOval方法似乎当油漆样式设置为Paint.Style.STROKE绘制一个矩形,而不是圆的。 如果油漆风格设置为Paint.Style.FILL或FILL_AND_STROKE,一切似乎都很好。 看看它在下一张照片中的外观。在Android 6.0 drawOval中绘制一个矩形,当油漆样式设置为Pain.Style.STROKE

Pre Android 6

预的Android 6

Android 6

的Android 6

绿色矩形被认为是从标尺绿色圆圈

不e绘图是以1.0f乘以1.0f尺寸的矩形制成的。 除了6.0以外的所有Android版本,一切正常。

谢谢

回答

1

我通过使用重新缩放画布更大的矩形(100×100)的辅助功能进行管理,绘制圆和规模在画布到原来的大小。

public static void drawOval(Canvas canvas, RectF rectangle, Paint paint, float scale) { 
    float originalStrokeWidth = paint.getStrokeWidth(); 
    float upScaling = 100f; 
    paint.setStrokeWidth(originalStrokeWidth * upScaling); 
    canvas.save(); 
    RectF newRect = new RectF(); 
    newRect.left = rectangle.left*upScaling; 
    newRect.top = rectangle.top*upScaling; 
    newRect.right = rectangle.right*upScaling; 
    newRect.bottom = rectangle.bottom*upScaling; 
    canvas.scale(scale/upScaling, scale/upScaling); 
    canvas.drawOval(newRect, paint); 
    canvas.restore(); 
    paint.setStrokeWidth(originalStrokeWidth); 
} 
public static void drawOval(Canvas canvas, RectF rectangle, Paint paint) { 
    drawOval(canvas, rectangle, paint, 1f); 
} 

所以,在这里我不得不canvas.drawOval(RECT,油漆)我 CanvasUtils.drawOval(帆布,矩形,油漆)取代它;

我已经注意到,“错误”当我使用位图作为画布绘制图作为计的背景下才会发生。