将画布绘制为Drawable

时间:2011-11-04 20:40:28

标签: android android-layout

我正在尝试将Canvas放入Drawable ...下面的代码......任何帮助都表示赞赏!!

Drawable marker = makeMarker();
boundCenterBottom(marker);
item.setMarker(marker);

private Drawable makeMarker(){
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL); 
    paint.setColor(Color.BLACK);
    paint.setTextSize(20);

    Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    c.drawText("Some Text", 100, 100, paint);

    Drawable d = new BitmapDrawable(b);
    d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    return d;
}

1 个答案:

答案 0 :(得分:0)

getIntrinsicWidth()不适用于事件onCreate()并且等于零。所以,没有什么幸福的