2017-06-12 93 views
-1

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

我找不到任何地方的例子,所以也許這是不可能的。

回答

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.