[英]Alignment on Android Wear Watch Face
I am new to android watch face development and facing some problem with alignment of time text! 我是android表盘开发的新手,并且遇到时间文本对齐问题! I am displaying time in two format, How can I display it one at top and one at bottom and center aligned as shown in image below? 我以两种格式显示时间,如何将其显示在顶部,底部和中央对齐,如下图所示? Is there any pattern or layout for this? 是否有任何图案或布局?
It's up to you to figure out the alignment yourself when calling Canvas.drawText
in your onDraw
handler. 在onDraw
处理程序中调用Canvas.drawText
,由您自己确定对齐方式。 I use code something like this: 我使用如下代码:
String msg = "Text to display";
float width = paint.measureText(msg);
canvas.drawText(msg, centerX - width / 2f, top, paint);
where paint
, top
, and centerX
were all initialized previously. 其中paint
, top
和centerX
之前都已初始化。 The first two will depend on your face design, while the third is a Point
field that can be set in your onCreate
handler like so: 前两个取决于您的脸部设计,而第三个是可以在onCreate
处理程序中设置的Point
字段,如下所示:
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
display.getSize(displaySize);
centerX = displaySize.x / 2f;
Alternately, you could do all of this in XML with a layout-based watch face , but this may or may not be a good fit for your needs. 或者,您可以使用基于布局的表盘以XML的形式完成所有这些操作,但这可能无法满足您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.