2
當我看着的解決方案:如何確定Widget中的TextView寬度?
How to use a custom typeface in a widget
在上面的問題,我用一個Widget自定義字體; 使用的溶液:
public Bitmap buildUpdate(String time)
{
Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface clock = Typeface.createFromAsset(this.getAssets(),"Clockopia.ttf");
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setTypeface(clock);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(65);
paint.setTextAlign(Align.CENTER);
myCanvas.drawText(time, 80, 60, paint);
return myBitmap;
}
問題:如何確定根據字符數所產生的位圖的寬度和高度?
我需要增加寬度和高度,以便字體可以正確顯示 - > int widthOffset = Utils.dip2px(context,12); int heightOffset = Utils.dip2px(context,3);位圖myBitmap = Bitmap.createBitmap(rect.width(),size,Bitmap.Config.ARGB_4444); – see2851