Libgdx 如何在滚动窗格顶部对齐表格?

Libgdx 如何在滚动窗格顶部对齐表格?,libgdx,stage,Libgdx,Stage,我正在我的libgdx游戏中取得成就。我想将滚动窗格中的表格与顶部对齐,现在它垂直和水平居中,我不知道为什么。尝试创建新行时使用.top()方法无效 stage = new Stage(); Gdx.input.setInputProcessor(stage); outerTable = new Table(); innerTable = new Table(); innerTable.setFillParent(true); for

我正在我的libgdx游戏中取得成就。我想将滚动窗格中的表格与顶部对齐,现在它垂直和水平居中,我不知道为什么。尝试创建新行时使用
.top()
方法无效

stage      = new Stage();
    Gdx.input.setInputProcessor(stage);
    outerTable = new Table();
    innerTable = new Table();



    innerTable.setFillParent(true);



    for(int i=0;i<score_bound; i++){

        if(i<score_state){
         innerTable.row().width(achie_width).height(achie_height).top();

         innerTable.add(new Image(ltm.assets.score_textures[i]));
        }else{

            innerTable.row().width(achie_width).height(achie_height).top();

             innerTable.stack(new Image(ltm.assets.score_textures[i]),new Image(ltm.assets.kurtyna));

        }

    }

    for(int i=0;i<letin_bound; i++){

        if(i<letin_state){
             innerTable.row().width(achie_width).height(achie_height).top();

             innerTable.add(new Image(ltm.assets.letin_textures[i]));
            }else{

                innerTable.row().width(achie_width).height(achie_height).top();

                 innerTable.stack(new Image(ltm.assets.letin_textures[i]),new Image(ltm.assets.kurtyna));

            }

    }

    scrollPane = new ScrollPane(innerTable); 


    outerTable.setPosition(0, 0);
    outerTable.setSize(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());



    outerTable.debug();

    outerTable.add(scrollPane).fill().expand();


    stage.addActor(outerTable);
stage=newstage();
Gdx.input.setInputProcessor(阶段);
outerTable=新表();
innerTable=新表();
innerTable.setFillParent(true);

对于(inti=0;i我今天遇到了同样的问题,在这里遇到了,所以我不妨在这里发布一个答案,以防有人仍在寻找答案

@Petersweeter说top()不起作用,@Rara的建议与调用top是一样的

实现类似于顶部对齐的功能的唯一方法是通过在其周围添加空元素来增加大小,从而使传递给滚动窗格的表至少与滚动窗格具有相同的大小,这仅在innerTable较小时才相关

我只是在innerTable引用周围包装了另一个表。 (658是我用于滚动窗格的固定高度)

Table spacingTable=new Table();
setHeight(Math.max(innerTable.getHeight(),658));
spacingTable.add(内部表);
if(innerTable.getHeight()<658){
spacingTable.row();
spacingTable.add().expandY();
}
滚动窗格滚动=新滚动窗格(间隔表、皮肤);

为了实现您的目标,您可以将您的表包装到另一个表中,并将该表用于滚动窗格。请注意,将表添加到容器表时,您需要在底部和右侧添加一些可扩展的空单元格,以便将其“推”到左上角(尽管我相信您也可以简单地使用containerTable.add)(myTable).top().left()-但尚未真正测试)。
这当然比second的解决方案要好得多,后者使用硬编码的高度。问题是,您通常希望将滚动窗格添加为可增长(.grow()),因此固定的高度/宽度是无用的。

尝试更改
outerTable.add(scrollPane).fill().expand();
outerTable.add(scrollPane).fill().expand().align(align.top);
    Table spacingTable = new Table();
    spacingTable.setHeight(Math.max(innerTable.getHeight(), 658));
    spacingTable.add(innerTable);

    if (innerTable.getHeight() < 658) {
        spacingTable.row();
        spacingTable.add().expandY();
    }

    ScrollPane scroll = new ScrollPane(spacingTable, skin);