2017-04-21 44 views
-2

我試圖在Android手錶臉上繪製圖標,但沒有在手錶臉上看到。 我已經檢查過這個鏈接。 Ref我在複雜性TYPE文本的錶盤上設置了文本,但它沒有設置爲像ICON,RANGED_VALUE,SMALL_IMAGE等其他類型,所以請建議。如何在ICON,RANGED_VALUE,SMALL_IMAGE的手錶上設置複雜功能在Android Wear

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

你是怎樣嘗試繪製呢?很難看出你在哪裏出問題。你能否請包括一些更多的信息/代碼?它失敗的地方在哪裏?你有這個圖標但不能畫出來嗎?也許你根本沒有得到這個圖標? –

+0

我添加圖片,以便您瞭解我的觀點。 –

+0

到目前爲止您嘗試過什麼?你甚至有任何代碼向我們展示? – Gattsu

回答

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