2021年1月16日星期六

Libgdx Android- Why is my Button widget huge and exceed the Table widget?

I have used Libgdx. I am still new to Scene2d and Scene2d.ui, for trying to make a menu screen. In the IntelliJ IDE, using the Libgdx framework, I am trying to make an android application. Since I am using screens, I changed my Application Adapter to a Game, and in the create method, I created and set a screen that I made, the HomeScreen class. The constructor of this class has the following code:

//Creating and Initialising fields  camera = new OrthographicCamera();  viewport = new ExtendViewport(50, 100, camera);  stage = new Stage();  table = new Table();  skin = new Skin(Gdx.files.internal("Glassy Skin/glassy-ui.json"));    //More Setup  stage.setViewport(viewport);  table.setFillParent(true);  stage.addActor(table);  table.setDebug(true);  table.setSize(50, 100);    tableSetup();  

And the tableSetup() method looks like this:

        TextButton button = new TextButton("Test", skin);          button.addListener(new ClickListener(){              @Override              public void clicked(InputEvent event, float x, float y){                  System.out.println("CLICKED");              }          });          table.add(button).expandX();  

Also, I do set the stage as the input processor in the HomeScreen class's show method. When I run my code, to try to have a glassy skin text button with the text "test" appear, I get this:The Glassy Skin TextButton really zoomed in. Using the zoom feature on the camera, I was able to see that while the table widget's size was equal to the screen, the table cell was much larger and exceeded the size of the table widget. I tried using table.add(button).width(50), but that didn't do it. I even tried table.add(button).prefSize(), and table.add(button).maxSize(). Could someone please help me figure out why this is happening? Also, please try to explain in simple words/language as I am only in high school.

EDIT: I moved to a different project and tried adding the stage, table, and button. Apparently, when adding a label instead of a button, it was not too big, but when I tried the button, the button was huge! I don't know how to fix the size of the button, that is the real question.

https://stackoverflow.com/questions/65730413/libgdx-android-why-is-my-button-widget-huge-and-exceed-the-table-widget January 15, 2021 at 12:13PM

没有评论:

发表评论