Android Staticlayout字体大小

时间:2011-05-18 12:52:41

标签: android canvas fonts font-size

无论如何都要改变静态布局的字体大小?这就是我到目前为止所展示的内容 文本在正确的位置开始。

int question_text_width = game_question_bg.getWidth();
int question_text_xPos = 100;
int question_text_yPos = 100;

StaticLayout question_text = new StaticLayout(text, text_paint, question_text_width, Layout.Alignment.ALIGN_CENTER, 1.2f, 1.0f, false);

//Position Text
canvas.translate(question_text_xPos, question_text_yPos);

//As a form of setMaxLine
canvas.clipRect(new Rect(0, 0, game_question_bg.getWidth(), game_question_bg.getHeight()));

question_text.draw(canvas);

//Reset canvas back to normal
canvas.restore();

1 个答案:

答案 0 :(得分:10)

您可以使用在创建StaticLayout时作为参数传递的TextPaint来设置字体大小:

TextPaint text_paint = new TextPaint();
float fontSize = 25;
text_paint.setTextSize(fontSize);
StaticLayout question_text = new StaticLayout(text, text_paint, question_text_width, Layout.Alignment.ALIGN_CENTER, 1.2f, 1.0f, false);