本文介绍了如何在 Android Wear 上的 ICON、RANGED_VALUE、SMALL_IMAGE 表盘上设置复杂度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 android 表盘上绘制图标,但在表盘上没有看到.我已经检查过这个链接.

我需要这种带有红色标记复杂功能的类型图标.我使用此代码绘制文本.

if (COMPLICATION_IDS[i] == RIGHT_DIAL_COMPLICATION) {//RIGHT_DIAL_COMPLICATION 计算int offset = (int) ((mWidth/2) - textWidth)/2;并发症X =(mWidth/2)+偏移量;canvas.drawText(并发症消息,0,complicationMessage.length(),并发症X,m并发症Y,mComplicationPaint);Log.e("log", "offset==" + offset + "==complicationsX==" +complicationsX);Log.e("log", "mComplicationsY==" + mComplicationsY);}

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

if (COMPLICATION_IDS[i] == LEFT_DIAL_COMPLICATION) {并发症X = (int) ((mWidth/2) - textWidth)/2;图标 icon = complicationData.getIcon();Drawable drawable = icon.loadDrawable(getApplicationContext());如果(BitmapDrawable 的可绘制实例){位图位图;位图 = ((BitmapDrawable) drawable).getBitmap();canvas.drawBitmap(位图,complicationsX,mComplicationsY,null);}}
解决方案

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

Icon icon = complicationData.getIcon();如果(图标!= null){Drawable drawable = icon.loadDrawable(getApplicationContext());如果(可绘制!= null){drawable.setBounds(20, 20, 50, 50);//左,上,右,下drawable.draw(画布);}}

I tried to draw icon on android watch face but did not see on watch face.I already check this link.Ref I set text on watchface for complication TYPE text but it does not set for other type like ICON,RANGED_VALUE,SMALL_IMAGE so please suggest.

I need this type icon where red mark complication.I used this code for draw text.

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);

                    }

and use this code for image but not getting any thing.

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);
                        }
                    } 
解决方案

No need to create a bitmap instance, just set the drawable bounds use it's draw method:

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);
    }
}

这篇关于如何在 Android Wear 上的 ICON、RANGED_VALUE、SMALL_IMAGE 表盘上设置复杂度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:55