Canvas.drawTextOnPath(...)不工作棒棒糖 [英] Canvas.drawTextOnPath(...) not working on Lollipop
问题描述
canvas.DrawTextOnPath似乎并没有工作棒棒糖设备上。看到其中的差别在这里。 (Nexus的10 形象是正确的,但棒棒堂不会正确显示)
canvas.DrawTextOnPath does not seem to work on a Lollipop device. See the difference here. (The Nexus 10 image is correct but Lollipop does not display correctly)
在code是一个简单的路径平局。
The code is a simple path draw.
// 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的Studio测试项目说明这个问题可以看这里的人谁愿意看到它。 https://dl.dropboxusercontent.com/u/6768304/WebLinks/TestApp.rar
The Android Studio test project illustrating this issue can be seen here for anyone who wants to see it. https://dl.dropboxusercontent.com/u/6768304/WebLinks/TestApp.rar
有什么不同我需要做此设备上?
Is there something "different" I need to do on this device?
推荐答案
确定这样看来,DrawTextOnPath被一点点打破现在低于1.0F的字体大小
OK so it seems that DrawTextOnPath is a little broken now with font sizes below 1.0f
解决的办法是按比例的一切行动,绘制文本又缩了回去。
The solution is to scale everything up, draw the text then shrink it back down.
在示范项目的drawTitle方法将改变从这样的:
The drawTitle method in the demo project would change from this:
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);
}
这篇关于Canvas.drawTextOnPath(...)不工作棒棒糖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!