Scene2d:如何在屏幕底部放置一个小部件,在顶部放置另一个小部件?

Scene2d: How to place a widget at the bottom of the screen and another one at the top?

我想要 ScrollPane with two Labels above a Button 总是 留在屏幕底部。如果这些标签中的文本太多,则可以正常滚动。但是如果只有几行,按钮就停留在ScrollPane的正下方,所以可能会出现按钮在屏幕中间的情况。

这是我的代码:

    Table container = new Table();
    container.setFillParent(true);
    container.top();

    Table table = new Table();

    ScrollPane scrollPane = new ScrollPane(table);
    scrollPane.setOverscroll(false, false);

    Label label1 = new Label(text1, labelStyle);

    Label label2 = new Label(text2, labelStyle);
    label2.setWrap(true);

    Button button = new Button(buttonStyle);

    table.add(label1).pad(paddingText);
    table.row();
    table.add(label2).pad(0, paddingText, 0, paddingText).width(stage.getViewport().getWorldWidth() - 2 * paddingText);

    container.add(scrollPane);
    container.row();
    container.add(button).pad(paddingButton).bottom();

    stage.addActor(container);

它应该是这样的:

看看 Cell#fill 和 Cell#expand 方法:

table.add(...).fillY().expandY();

这将扩展 Y 轴上的单元格并填充它。