Canvas.drawTextOnPath(…)不适用于棒棒糖

canvas.DrawTextOnPath似乎不适用于棒棒糖设备。 看到这里的区别。 (Nexus 10图像正确,但棒棒糖显示不正确)

图片

代码是一个简单的path绘制。

// Path for the inner circle unitPath = new Path(); unitPath.addArc(unitRect, 180.0f, 180.0f); // Draw the text and the path canvas.drawTextOnPath("Inner Circle", unitPath, 0.0f, 0.0f, unitPaint); canvas.drawPath(unitPath,unitPaint); 

任何想看到它的人都可以在这里看到解决这个问题的Android Studiotesting项目。 https://dl.dropboxusercontent.com/u/6768304/WebLinks/TestApp.rar

在这个设备上需要做什么“不同的”?

Solutions Collecting From Web of "Canvas.drawTextOnPath(…)不适用于棒棒糖"

好吧,看起来DrawTextOnPath现在有点破碎,字体大小低于1.0f

解决办法是将所有东西都缩小,绘制文本然后缩小。

演示项目中的drawTitle方法将由此改变:

 private void drawTitle(Canvas canvas) { canvas.drawTextOnPath(upperTitle, upperTitlePath, 0.0f, 0.02f, unitPaint); canvas.drawTextOnPath(lowerTitle, lowerTitlePath, 0.0f, 0.0f, unitPaint); canvas.drawTextOnPath(unitTitle, unitPath, 0.0f, 0.0f, unitPaint); canvas.drawPath(unitPath,unitPaint); } 

对此:

 private void drawTitle(Canvas canvas) { //Save original font size float originalTextSize = unitPaint.getTextSize(); // set a magnification factor final float magnifier = 100f; // Scale the canvas canvas.save(); canvas.scale(1f / magnifier, 1f / magnifier); // create new rects and paths based on the new scale unitRect = new RectF(); unitRect.set((faceRect.left + unitPosition) * magnifier, (faceRect.top + unitPosition) * magnifier, (faceRect.right - unitPosition) * magnifier, (faceRect.bottom - unitPosition) * magnifier); unitPath = new Path(); unitPath.addArc(unitRect, 180.0f, 180.0f); titleRect = new RectF(); titleRect.set((faceRect.left + titlePosition) * magnifier, (faceRect.top + titlePosition) * magnifier, (faceRect.right - titlePosition) * magnifier, (faceRect.bottom - titlePosition) * magnifier); upperTitlePath = new Path(); upperTitlePath.addArc(titleRect, 180.0f, 180.0f); titleRect = new RectF(); titleRect.set((faceRect.left + titlePosition) * magnifier, (faceRect.top + titlePosition) * magnifier, (faceRect.right - titlePosition) * magnifier, (faceRect.bottom - titlePosition) * magnifier); lowerTitlePath = new Path(); lowerTitlePath.addArc(titleRect, -180.0f, -180.0f); // increase the font size unitPaint.setTextSize(originalTextSize * magnifier); // do the drawing of the text canvas.drawTextOnPath(unitTitle, unitPath, 0.0f, 0.0f, unitPaint); canvas.drawTextOnPath(upperTitle, upperTitlePath, 0.0f, 0.02f, unitPaint); canvas.drawTextOnPath(lowerTitle, lowerTitlePath, 0.0f, 0.0f, unitPaint); // bring everything back to normal canvas.restore(); unitPaint.setTextSize(originalTextSize); canvas.drawPath(unitPath, unitPaint); } 

是的,破碎的棒棒糖。 在4.4.4中完美工作。

https://code.google.com/p/android/issues/detail?id=40965

如果尺寸较小,则将文本大小设置为5.f,缩小canvas并适当缩放基准path。 慢,但它的工作,不能等到我可以删除这个可怕的混乱。