java - 无法设置 scene2d.ui.Dialog 大小

标签 java android opengl-es libgdx scene2d

我正在尝试在屏幕中间显示一个对话框。但我无法使用 setWidth() 或 setHeight() 更改对话框的大小。我有以下代码:

private void showDialog() {
    Window.WindowStyle dialogStyle = new Window.WindowStyle();
    dialogStyle.background = new TextureRegionDrawable(new TextureRegion(dialog_bg));
    dialogStyle.titleFont = gameFont;
    Dialog dialog = new Dialog("Test Dialog", dialogStyle);
    dialog.setWidth(200);   // will be ignored
    dialog.show(stage);
}

有什么想法吗?

最佳答案

只需在调用 dialog.show() 后调用对大小的更改。在本例中,我使用的是带有 FitViewport 的舞台,因此我缩小了我的 Actor 以使其适合。当我调整它们的大小时,我必须考虑比例。

public void create(Dialog dialog, float scale){
    dialog.setScale(scale);
    dialog.setMovable(false);

    dialog.text("Are you sure you want to yada yada?");
    dialog.button("Yes", true); //sends "true" as the result
    dialog.button("No", false); //sends "false" as the result
}

public void show(Stage st) {
    dialog.show(st); //pack() is called internally
    dialog.setWidth(worldWidth/scale); //we override changes made by pack()
    dialog.setY(Math.round((st.getHeight() - dialog.getHeight()) / 2)); //we override changes made by pack()
}

关于java - 无法设置 scene2d.ui.Dialog 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25352102/

相关文章:

java - 正则表达式检索任何字母数字 otp 代码

java - 在Java中为类的参数设置值

android - 即使没有 Activity 运行,如何使服务运行?

iOS:在初始化期间获取 View 大小

java - 解析 JSONObjects 和 JSONArrays 的最佳方式

java - 使用 Java 将文件 .pptx 转换为图像

android - 混淆器 - PersistenceException : Constructor not matched for class

android - JNI 与安卓?

android - libgdx:android 构建有图形故障

java - 在 CardboardView 上显示的 YUV 视频