如何在Android上佩戴ICON,RANGED_VALUE,SMALL_IMAGE的表盘上设置复杂功能

时间:2017-04-21 09:07:00

标签: android types watchface android-wear-complication

我试图在Android表盘上绘制图标,但没有在表盘上看到。 我已经检查了这个链接。Ref我在watchface上为复杂的TYPE文本设置了文本,但它没有设置其他类型,如ICON,RANGED_VALUE,SMALL_IMAGE所以请建议。

I need this type icon where red mark complication.

我需要这种类型的图标,其中红色标记复杂。 我将此代码用于绘制文本。

if (COMPLICATION_IDS[i] == RIGHT_DIAL_COMPLICATION) {
                        // RIGHT_DIAL_COMPLICATION calculations
                        int offset = (int) ((mWidth / 2) - textWidth) / 2;
                        complicationsX = (mWidth / 2) + offset;
                        canvas.drawText(
                                complicationMessage,
                                0,
                                complicationMessage.length(),
                                complicationsX,
                                mComplicationsY,
                                mComplicationPaint);
                        Log.e("log", "offset==" + offset + "==complicationsX==" + complicationsX);
                        Log.e("log", "mComplicationsY==" + mComplicationsY);

                    }

并将此代码用于图像,但没有得到任何东西。

if (COMPLICATION_IDS[i] == LEFT_DIAL_COMPLICATION) {
                        complicationsX = (int) ((mWidth / 2) - textWidth) / 2;

                        Icon icon = complicationData.getIcon();
                        Drawable drawable = icon.loadDrawable(getApplicationContext());
                        if (drawable instanceof BitmapDrawable) {
                            Bitmap bitmap;
                            bitmap = ((BitmapDrawable) drawable).getBitmap();
                            canvas.drawBitmap(bitmap, complicationsX, mComplicationsY, null);
                        }
                    } 

1 个答案:

答案 0 :(得分:0)

无需创建位图实例,只需设置可绘制边界即可使用它的绘制方法:

Icon icon = complicationData.getIcon();
if(icon != null) {
    Drawable drawable = icon.loadDrawable(getApplicationContext());
    if(drawable != null) {
        drawable.setBounds(20, 20, 50, 50); //left, top, right, bottom
        drawable.draw(canvas);
    }
}