我将要开发一个需要在Canvas上拖放的应用程序.基本上,我想获取一个ShapeDrawable并将其转换为位图,我可以让用户在屏幕上拖动.这本身就是一个简单的练习.
但是,我想在形状内添加文本.有没有一种方法可以将文本添加到可绘制对象本身,然后转换为位图?我研究了如何以可绘制背景为背景的TextView.
这是最好的方法吗?我有点想避免在我的代码中创建TextViews.任何建议表示赞赏.
编辑2/21/2013:
回应JustDanyul的帖子,我有以下代码:
int width = 40;
int height = 40;
Bitmap.Config config = Bitmap.Config.ARGB_8888;
bitmap = Bitmap.createBitmap(width, height, config);
Canvas canvas = new Canvas(bitmap);
Resources res = context.getResources();
Drawable shape = res.getDrawable(R.drawable.miss_scarlet);
shape.draw(canvas);
Paint paint = new Paint();
paint.setTextSize(fontSize);
paint.setColor(Color.BLACK);
canvas.drawText(gameToken.getDbName(), 5, 5, paint);
当我在另一个画布上绘制位图时,我的可绘制对象没有显示. drawable本身很好(我将其作为TextView的背景进行了测试).文本显示出来.我在此代码中缺少什么吗?
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
android:radius="4dp" />
android:color="#FF0000" />
android:width="3dp"
android:color="#000000" />
编辑#2 2/21/2013:
我补充说:
shape.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
到我的代码,现在可绘制对象出现了,但是我的文本消失了(或只是隐藏了).