JAVA-LIBGDX如何正确设置滚动窗格

JAVA-LIBGDX如何正确设置滚动窗格,java,user-interface,libgdx,scrollpane,Java,User Interface,Libgdx,Scrollpane,我正试图在我的游戏中添加一个屏幕底部滑动较少的菜单(左和右)。 我的问题是我无法调整屏幕底部的表格,这是我的代码: private void initUI() { // inizializzazione dello stage stage = new Stage(new ExtendViewport(Gdx.graphics.getWidth(),Gdx.graphics.getHeight()/4)); Skin skin = new Skin(Gdx.files.inter

我正试图在我的游戏中添加一个屏幕底部滑动较少的菜单(左和右)。 我的问题是我无法调整屏幕底部的表格,这是我的代码:

   private void initUI() {
  // inizializzazione dello stage
  stage = new Stage(new ExtendViewport(Gdx.graphics.getWidth(),Gdx.graphics.getHeight()/4));
  Skin skin = new Skin(Gdx.files.internal("ui/uiskin.json"));
  Gdx.input.setInputProcessor(stage);

  // inizializzazione della tabella 
  container = new Table();
  container.setFillParent(true);
  stage.addActor(container);

  Table table = new Table();
  table.debug();

  final ScrollPane scroll = new ScrollPane(table, skin);
  scroll.setFillParent(true);

  InputListener stopTouchDown = new InputListener() {
     public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        event.stop();
        return false;
     }         
  };

  table.pad(20).defaults().expandY().space(5);

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

     table.row();
     TextButton button = new TextButton(i + "dos", skin);
     table.add(button);
     button.addListener(new ClickListener() {
        public void clicked (InputEvent event, float x, float y) {
           System.out.println("click " + x + ", " + y);
        }
     });
  }      

  container.add(scroll).expandY().fill().colspan(1);
  container.row().space(10).padBottom(10);
}

通过这种方式,我可以将屏幕分为两部分(顶部和底部),但输入不正确:要激活第一个按钮,我必须按下屏幕顶部,但底部的按钮是“设计”的


如何使用屏幕底部的滚动窗格创建表格?

对于视口、表格以及如何使用它们,似乎存在一些误解:

使用一个
视口
渲染整个屏幕。使用
表格
拆分屏幕。因此,将
initUI
中的第一行更改为

stage=newstage(新的extendedviewport(Gdx.graphics.getWidth(),Gdx.graphics.getHeight())(卸下/4)

并将渲染方法调整为类似以下内容:

 @Override
 public void render(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 0);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.
        stage.act(delta);
        stage.draw();
 }
清除颜色缓冲区,以确保正确绘制动画或按钮按下操作。不要将
stage
设置为
InputProcessor
每个帧调用。在
initUI
中完成此操作后,一切正常

表的大小:我假设表与包含的元素不匹配。因此,每次在
表格中添加按钮时。添加(按钮)
表格中添加有关其高度和宽度的信息。添加(按钮)。高度(…)。宽度(…)
。然后将表格和相应的滚动窗格向右调整


目前我只看到
容器
包含填充其父对象的
滚动
对象,该父对象填充整个屏幕。因此,在
container.row().space(10).padboottom(10)之后,确保在将
scroll
添加到
container
之后,向容器中再添加一个表。此表将绘制在滚动窗格下方。

谢谢,我已经完成,这是我的新代码:

    // inizializzazione dello stage
    stage = new Stage(new ExtendViewport(Constants.VIEWPORT_GUI_WIDTH,Constants.VIEWPORT_GUI_HEIGHT/4));
    Skin skin = new Skin(Gdx.files.internal("ui/uiskin.json"));
    Gdx.input.setInputProcessor(stage);

    // inizializzazione della tabella 
    container = new Table();
    container.setFillParent(true);
    container.bottom();
    stage.addActor(container);

    Table table = new Table();
    table.debug();
    table.bottom();

    final ScrollPane scroll = new ScrollPane(table, skin);
    //scroll.setFillParent(true);
    scroll.setupFadeScrollBars(0f, 0f);

    InputListener stopTouchDown = new InputListener() {
        public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return false;
        }           
    };

    table.pad(20).defaults().space(5);

    for (int i = 0; i < 15; i++) {
        TextButton button = new TextButton(i + "dos", skin);
        table.add(button).height(scroll.getHeight()).width(Constants.VIEWPORT_GUI_WIDTH/8);
        button.addListener(new ClickListener() {
            public void clicked (InputEvent event, float x, float y) {
                System.out.println("click " + x + ", " + y);
            }
        });
    }       
    container.bottom();
    container.add(scroll).height(Gdx.graphics.getHeight()/3);//.expandY().fill().colspan(1);
    container.row().space(10).padBottom(10);
//Izzazione dello舞台
stage=newstage(新的ExtendViewport(常数.视口\图形用户界面宽度,常数.视口\图形用户界面高度/4));
皮肤=新皮肤(Gdx.files.internal(“ui/uiskin.json”);
Gdx.input.setInputProcessor(阶段);
//塔贝拉酒店
容器=新表();
container.setFillParent(true);
容器。底部();
stage.addActor(容器);
Table Table=新表();
table.debug();
表1.bottom();
最终滚动窗格滚动=新滚动窗格(表、皮肤);
//scroll.setFillParent(true);
滚动条(0f,0f);
InputListener stopTouchDown=新建InputListener(){
公共布尔接地(InputEvent事件、浮点x、浮点y、整数指针、整数按钮){
事件停止();
返回false;
}           
};
table.pad(20).defaults().space(5);
对于(int i=0;i<15;i++){
text按钮=新的text按钮(i+“dos”,皮肤);
table.add(按钮).height(scroll.getHeight()).width(Constants.VIEWPORT\u GUI\u width/8);
addListener(新建ClickListener(){
已单击公共无效(InputEvent事件、浮点x、浮点y){
System.out.println(“单击“+x+”、“+y”);
}
});
}       
容器。底部();
container.add(scroll).height(Gdx.graphics.getHeight()/3);//。expandY().fill().colspan(1);
container.row().space(10).焊盘底部(10);
    // inizializzazione dello stage
    stage = new Stage(new ExtendViewport(Constants.VIEWPORT_GUI_WIDTH,Constants.VIEWPORT_GUI_HEIGHT/4));
    Skin skin = new Skin(Gdx.files.internal("ui/uiskin.json"));
    Gdx.input.setInputProcessor(stage);

    // inizializzazione della tabella 
    container = new Table();
    container.setFillParent(true);
    container.bottom();
    stage.addActor(container);

    Table table = new Table();
    table.debug();
    table.bottom();

    final ScrollPane scroll = new ScrollPane(table, skin);
    //scroll.setFillParent(true);
    scroll.setupFadeScrollBars(0f, 0f);

    InputListener stopTouchDown = new InputListener() {
        public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return false;
        }           
    };

    table.pad(20).defaults().space(5);

    for (int i = 0; i < 15; i++) {
        TextButton button = new TextButton(i + "dos", skin);
        table.add(button).height(scroll.getHeight()).width(Constants.VIEWPORT_GUI_WIDTH/8);
        button.addListener(new ClickListener() {
            public void clicked (InputEvent event, float x, float y) {
                System.out.println("click " + x + ", " + y);
            }
        });
    }       
    container.bottom();
    container.add(scroll).height(Gdx.graphics.getHeight()/3);//.expandY().fill().colspan(1);
    container.row().space(10).padBottom(10);