在 WatchFaceService 的 onCreateEngine() 中,获取充气机:
mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
然后在你的引擎的 onCreate() 中,膨胀你的布局:
mFrameLayout = (FrameLayout) mInflater.inflate(R.layout.main, null);
然后在 onDraw() 中,测量、布局和绘制视图:
//Measure the view at the exact dimensions (otherwise the text won't center correctly)
int widthSpec = View.MeasureSpec.makeMeasureSpec(bounds.width(), View.MeasureSpec.EXACTLY);
int heightSpec = View.MeasureSpec.makeMeasureSpec(bounds.height(), View.MeasureSpec.EXACTLY);
mFrameLayout.measure(widthSpec, heightSpec);
//Lay the view out at the rect width and height
mFrameLayout.layout(0, 0, bounds.width(), bounds.height());
mFrameLayout.draw(canvas);
只是不要指望用 TextClock 来做到这一点。它在 Android Wear 上不存在。显然,谷歌没有预料到开发者会想要在表盘上显示时钟!