【问题标题】:Android Staticlayout Font SizeAndroid Staticlayout 字体大小
【发布时间】:2011-08-28 01:07:48
【问题描述】:

有没有办法改变静态布局的字体大小?这是我到目前为止要展示的 文本在正确的位置开始。

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();

【问题讨论】:

    标签: android canvas fonts font-size


    【解决方案1】:

    您可以使用创建 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);
    

    【讨论】:

      猜你喜欢
      • 2012-11-26
      • 2016-09-18
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      • 2016-03-14
      • 2013-03-20
      • 1970-01-01
      • 2011-12-04
      相关资源
      最近更新 更多