【问题标题】:Scene2d: How to place a widget at the bottom of the screen and another one at the top?Scene2d:如何在屏幕底部放置一个小部件,在顶部放置另一个?
【发布时间】:2015-11-07 21:21:05
【问题描述】:

我希望有一个ScrollPane,在Button 上方有两个Labels,它始终 位于屏幕底部。如果这些标签内有这么多文本,这工作正常,滚动是可能的。但是如果只有几行,则按钮会停留在 ScrollPane 的正下方,因此可能会发生 Button 位于屏幕中间的情况。

这是我的代码:

    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#fillCell#expand方法:table.add(...).fillY().expandY();
  • 完美运行!将其添加为答案,我会接受。

标签: java user-interface layout libgdx scene2d


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2021-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多