【发布时间】:2012-02-03 16:41:12
【问题描述】:
我想在画布内绘制文本(需要时自动添加新行)。这是我的示例代码:
Bitmap src= getBitmap();
Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
Canvas cs = new Canvas(dest);
cs.drawBitmap(src, 0f, 0f, null);
TextPaint tp= new TextPaint();
tp.setTextSize(.....);
tp. //Custom the text properties
StaticLayout sl= new StaticLayout(text, tp, src.getWidth(), Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
sl.draw(cs);
这适用于以 "center|top" 重力绘制文本。但我需要能够制作“中心|中心”和“中心|底部”。 给定画布 src 和 sl 很容易计算 sl 必须去的地方,但是 如何更改 StaticLayout 的“起点”以便为其添加填充?
谢谢
【问题讨论】:
标签: java android android-layout android-widget