【发布时间】:2016-03-11 13:03:03
【问题描述】:
【问题讨论】:
标签: android android-layout wear-os watch-face-api
【问题讨论】:
标签: android android-layout wear-os watch-face-api
在您的 onDraw 处理程序中调用 Canvas.drawText 时,由您自己确定对齐方式。我使用这样的代码:
String msg = "Text to display";
float width = paint.measureText(msg);
canvas.drawText(msg, centerX - width / 2f, top, paint);
其中paint、top 和centerX 之前都已初始化。前两个将取决于您的面部设计,而第三个是 Point 字段,可以在您的 onCreate 处理程序中设置,如下所示:
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
display.getSize(displaySize);
centerX = displaySize.x / 2f;
或者,您可以使用layout-based watch face 在 XML 中完成所有这些操作,但这可能适合也可能不适合您的需求。
【讨论】: