• <bdo id='2HQMM'></bdo><ul id='2HQMM'></ul>
    <legend id='2HQMM'><style id='2HQMM'><dir id='2HQMM'><q id='2HQMM'></q></dir></style></legend>

    <i id='2HQMM'><tr id='2HQMM'><dt id='2HQMM'><q id='2HQMM'><span id='2HQMM'><b id='2HQMM'><form id='2HQMM'><ins id='2HQMM'></ins><ul id='2HQMM'></ul><sub id='2HQMM'></sub></form><legend id='2HQMM'></legend><bdo id='2HQMM'><pre id='2HQMM'><center id='2HQMM'></center></pre></bdo></b><th id='2HQMM'></th></span></q></dt></tr></i><div id='2HQMM'><tfoot id='2HQMM'></tfoot><dl id='2HQMM'><fieldset id='2HQMM'></fieldset></dl></div>

      <small id='2HQMM'></small><noframes id='2HQMM'>

    1. <tfoot id='2HQMM'></tfoot>

      滑块在表格中始终具有默认宽度

      时间:2023-05-20
      <legend id='0ysjM'><style id='0ysjM'><dir id='0ysjM'><q id='0ysjM'></q></dir></style></legend>

      <small id='0ysjM'></small><noframes id='0ysjM'>

    2. <i id='0ysjM'><tr id='0ysjM'><dt id='0ysjM'><q id='0ysjM'><span id='0ysjM'><b id='0ysjM'><form id='0ysjM'><ins id='0ysjM'></ins><ul id='0ysjM'></ul><sub id='0ysjM'></sub></form><legend id='0ysjM'></legend><bdo id='0ysjM'><pre id='0ysjM'><center id='0ysjM'></center></pre></bdo></b><th id='0ysjM'></th></span></q></dt></tr></i><div id='0ysjM'><tfoot id='0ysjM'></tfoot><dl id='0ysjM'><fieldset id='0ysjM'></fieldset></dl></div>

          <tfoot id='0ysjM'></tfoot>

            <tbody id='0ysjM'></tbody>

              • <bdo id='0ysjM'></bdo><ul id='0ysjM'></ul>
                本文介绍了滑块在表格中始终具有默认宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我在表格内创建了一个滑块,如下面的代码示例所示,因为我知道背景的最小宽度用于滑块宽度:

                I created a slider inside of a table like shown in the following code example as I know that the minimum width of the background is used for the slider width:

                public OptionScreen(MainClass game) {
                    super(game);
                    preference = new PreferencesHelper();
                    font = this.getDefaultFont(25);
                    this.table = new Table();
                    if (Config.DEBUG)
                        this.table.debug();
                
                    // add volumenlabel
                    LabelStyle style = new LabelStyle(font, Color.WHITE);
                    volumenLabel = new Label(Config.VOLUMEN_LABLE, style);
                    table.add(volumenLabel).colspan(2);
                    table.row();
                    // add slider
                    Skin skin = new Skin();
                    skin.add("sliderbackground",
                            this.game.manager.get("data/sliderbackground.png"));
                    skin.add("sliderknob", this.game.manager.get("data/sliderknob.png"));
                
                    SliderStyle sliderStyle = new SliderStyle();
                    sliderStyle.background = skin.getDrawable("sliderbackground");
                    sliderStyle.background.setMinWidth(600f);
                    sliderStyle.knob = skin.getDrawable("sliderknob");
                
                    volumenSlider = new Slider(0f, 1f, 0.1f, false, sliderStyle);
                    volumenSlider.setValue(preference.getVolumen()); // load current volumen
                    volumenSlider.addListener(new ChangeListener() {
                
                        @Override
                        public void changed(ChangeEvent event, Actor actor) {
                            volumeValue.setText(String.format("%.01f",
                                    volumenSlider.getValue()));
                            // sett the preference
                            preference.setVolumen(volumenSlider.getValue());
                        }
                    });
                    // add volslider to stage
                    table.add(volumenSlider);
                    volumenLabel.invalidate();
                
                    // table
                    style = new LabelStyle(font, Color.WHITE);
                    // set current volumen
                    volumeValue = new Label(
                            String.format("%.01f", volumenSlider.getValue()), style);
                    volumenLabel.setAlignment(2);
                    table.add(volumeValue).width(50f);
                    table.row();
                
                    initBackButton();
                
                    // init table
                    table.setPosition(Config.VIRTUAL_VIEW_WIDTH / 2,
                            Config.VIRTUAL_VIEW_HEIGHT / 2 - Config.BLOCK_SIZE * 10);
                
                    // add a nice fadeIn to the whole table :)
                    table.setColor(0, 0, 0, 0f);
                    table.addAction(Actions.fadeIn(2f)); // alpha fade
                    table.addAction(Actions.moveTo(Config.VIRTUAL_VIEW_WIDTH / 2,
                            Config.VIRTUAL_VIEW_HEIGHT / 2, 2f)); // move to center of the
                                                                    // screen
                    // add to stage
                    this.stage.addActor(table);
                }
                

                幻灯片位于未设置宽度的表格内.我已经查看了是否设置了宽度以及滑块的 prefWidth 的计算是否使用了设置的 600f.

                The slide is inside a table with no width set. I already took a look if the width is set and if the calculation for the prefWidth of the slider does uses the set 600f.

                Math.max(style.knob == null ? 0 : style.knob.getMinWidth(), style.background.getMinWidth())
                

                是对Sliderclass里面的滑块宽度的计算.如果我计算并记录它,它会记录所需的 600f.

                Is the calculation for the width of the slider inside the Sliderclass. If I calculate that and log it, it loggs the desired 600f.

                一切对我来说似乎都是正确的,但是对于我设置的 600,滑块的渲染方式太小了.

                Everything seems right to me but the slider is rendered way to small for the 600 I set.

                背景和旋钮纹理是 24x24.

                The background and knobtextures are 24x24.

                所以我希望你们能告诉我我做错了什么.

                So I hope you guys can tell me what I am doing wrong.

                推荐答案

                解决方案是,它在表格内,因此宽度由规范的表格宽度属性定义.列和行.

                The folution is, that it's inside an table so the width is defined by the table width attibut for the spec. col and row.

                所以修复很短:

                table.add(volumenSlider).width(600).height(60);
                

                它的宽度为 600,高度为 60.

                And its 600width and 60 height.

                UI 小部件不设置自己的大小和位置.相反,父窗口小部件设置每个孩子的大小和位置.小部件提供父级可以用作提示的最小、首选和最大大小.一些父窗口小部件,例如 Table,可以限制子窗口的大小和位置.要在布局中为小部件指定特定尺寸,小部件的最小、首选和最大尺寸将保持不变,并且在父级中设置尺寸约束.

                UI widgets do not set their own size and position. Instead, the parent widget sets the size and position of each child. Widgets provide a minimum, preferred, and maximum size that the parent can use as hints. Some parent widgets, such as Table, can be given constraints on how to size and position the children. To give a widget a specific size in a layout, the widget's minimum, preferred, and maximum size are left alone and size constraints are set in the parent.

                在 Wiki 上布局

                这篇关于滑块在表格中始终具有默认宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:(Libgdx 1.6.1) BitmapFontCache.draw 由于索引超出范围而 下一篇:libgdx 多个对象实现 InputProcessor

                相关文章

                最新文章

                <legend id='AeHTz'><style id='AeHTz'><dir id='AeHTz'><q id='AeHTz'></q></dir></style></legend>
              • <small id='AeHTz'></small><noframes id='AeHTz'>

                  <tfoot id='AeHTz'></tfoot>
                  1. <i id='AeHTz'><tr id='AeHTz'><dt id='AeHTz'><q id='AeHTz'><span id='AeHTz'><b id='AeHTz'><form id='AeHTz'><ins id='AeHTz'></ins><ul id='AeHTz'></ul><sub id='AeHTz'></sub></form><legend id='AeHTz'></legend><bdo id='AeHTz'><pre id='AeHTz'><center id='AeHTz'></center></pre></bdo></b><th id='AeHTz'></th></span></q></dt></tr></i><div id='AeHTz'><tfoot id='AeHTz'></tfoot><dl id='AeHTz'><fieldset id='AeHTz'></fieldset></dl></div>
                      <bdo id='AeHTz'></bdo><ul id='AeHTz'></ul>