-1

我正在关注本教程,了解如何使用ComplicationDrawable. 我想不通的是如何ComplicationDrawable对内容做出响应?例如,如果底部复杂的数据类型是ComplicationData.TYPE_LONG_TEXT,我如何使我的ComplicationDrawable更宽以适应文本?

这是我如何绘制复杂性界限的代码

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

4

1 回答 1

1

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

// 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.
于 2017-06-13T14:54:06.433 回答