【问题标题】:Resize text in Textbutton在 Textbutton 中调整文本大小
【发布时间】:2013-07-22 10:40:52
【问题描述】:

大家好! 我正在尝试使用 libgdx 和 scene2d 设置 TextButton 中文本的大小。

以下是我创建和初始化 textbutton 对象的方法:

Skin skin = new Skin();
skin.add("white", new Texture(Gdx.files.internal("data/texture.jpg")));
skin.add("default", new BitmapFont());

TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.up = skin.newDrawable("white");
textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
textButtonStyle.font = skin.getFont("default");
skin.add("default", textButtonStyle);

TextButton newGame = new TextButton("Hello button",skin);

然后完美地创建了带有文本的按钮,但我不明白如何更改它的文本大小。

Label 对象的几乎所有方法我都已经尝试过了:

newGame.getLabel().setScale(10);
newGame.getLabel().setWidth(100);

等等。所以我的问题是:如何更改 TextButton 中的文字大小

【问题讨论】:

    标签: android libgdx


    【解决方案1】:

    尝试将字体比例设置为 Button 的标签。

    tb.getLabel().setFontScale(5.0f);

    【讨论】:

      【解决方案2】:

      尝试通过缩放来改变字体的大小。 textButtonStyle.font.setScale(..)

      我建议您查看FreeTypeFontGenerator,它可以帮助您创建不同大小的字体,而不是常规的.tff 文件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-04
        • 2017-12-29
        相关资源
        最近更新 更多