Android 佩戴表盘:WatchFaceService 中的 onDraw() 替代方案?

Android Wear Watch Face: onDraw() alternative in WatchFaceService?

如此处所述 (https://developer.android.com/training/wearables/watch-faces/service.html) 要绘制表盘,我必须使用 OnDraw 方法,对吗?没有其他选择吗?

这是在开玩笑吗? xml 管理层没有布局?没有dpi管理?没有屏幕格式管理?等等等等?

真的吗?

请告诉我我错了!

PS本页(http://www.binpress.com/tutorial/how-to-create-a-custom-android-wear-watch-face/120)使用正常活动制作表盘,是否正确?

你说得对,你必须使用 Canvas 或 OpenGL。 您提供的 link 解释了适用于 5.0 之前版本的旧解决方法。 现在,您必须使用新的 API.

在 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 上不存在。显然,Google 没想到开发人员会想要在表盘上显示时钟!