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

How do you make a complication adaptive?

I was following this tutorial 了解如何使用 ComplicationDrawable 向表盘添加复杂功能。我无法弄清楚的是如何使 ComplicationDrawable 响应内容?例如,如果底部复杂功能的数据类型是 ComplicationData.TYPE_LONG_TEXT,我如何使我的 ComplicationDrawable 更宽以适应文本?

Here is my code for how I'm drawing the bounds for the complications.

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

您的代码中已经包含了您需要的一切。唯一缺少的是根据并发症类型设置界限。我是这样做的:

// 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.