Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Staticlayout Font Size

Is there anyway to change the font size of a static layout? This what I have so far to display the text in the correct place to begin with.

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();
like image 425
Stevanicus Avatar asked May 18 '11 12:05

Stevanicus


1 Answers

You can set the font size using the TextPaint you pass as an argument when the StaticLayout is created:

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);
like image 82
TofferJ Avatar answered Sep 28 '22 09:09

TofferJ