你如何使复杂功能具有适应性



我正在按照本教程学习如何使用 ComplicationDrawable 为表盘添加复杂功能。我无法弄清楚的是,如何使ComplicationDrawable对内容做出响应?例如,如果底部复杂功能的数据类型为 ComplicationData.TYPE_LONG_TEXT ,如何使ComplicationDrawable更宽以针对文本进行调整?

这是我如何为复杂性划定界限的代码。

我在任何地方都找不到这样的例子,所以也许这是不可能的。

你的代码中已经有了你需要的一切。唯一缺少的是根据复杂类型设置边界。我是这样做的:

// Create a ComplicationDrawable object, and give it a Context.
ComplicationDrawable complicationDrawable = new ComplicationDrawable();
complicationDrawable.setContext(context);
// Set the ComplicationData from the onComplicationDataUpdate(int id, ComplicationData data) callback in your WatchFaceService.Engine class.
complicationDrawable.setComplicationData(data); 
// Set the bounds based on the current complication type.
Rect bounds = new Rect();
if (data.getType() == ComplicationData.TYPE_LONG_TEXT) {
    bounds.set(getLongTextBounds());
} else {
    bounds.set(getShortTextBounds());
}
complicationDrawable.setBounds(bounds);
// Set all other customization options, and draw the ComplicationDrawable to your canvas.

最新更新