滑块始终有默认宽度 [英] slider always has default width

查看:144
本文介绍了滑块始终有默认宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[更新] 我注意到一个无效()将是一件好事,但它并没有改变什么!所以我把整个optionlayout与创建表和滑块+标签。该后退按钮只是添加到表的最后一个TEXT按钮。我知道它很长的code,但我似乎有需要。

[UPDATE] I noticed that an invalidate() would be good but it didnt change something! So i put in the whole optionlayout with the creation of the table and the slider + labels. The backbutton is just a textbutton added to the end of the table. I know its a long code but i seems to be needed.

我创造了这样一个滑块,因为我知道,背景是了minWidth用于滑块宽度:

I created a slider like this as i know that the minwidth 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并把我的600

It's inside a table with no width or such. I already took a look if the width is sett and if the calculation for the prefWidth of the slider does take my 600.

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

这是计算为Sliderclass内滑动件的宽度。如果我计算出,并记录它,我得到的600
一切似乎我的权利,但滑块的方式来为小600我SETT。
背景和knobtextures是24×24。照片 所以,我希望你们能告诉我什么,我做错了。

this is the calculation for the width of the slider inside the Sliderclass. If i calculate that and log it, i get the 600.
Everything seems to me right but the slider is way to small for the 600 i sett.
Background and knobtextures are 24x24.
So i hope you guys can tell me what i am doing wrong.

推荐答案

我找到了解决办法。
其一个表内,从而在宽度由表宽度attibut为与规范中定义。山口和行。
因此,解决办法是$ P $帕蒂短。

I found the solution.
Its inside an table so the width is defined by the table width attibut for the spec. col and row.
So the fix is preaty short.

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

和其600width和60的高度。

And its 600width and 60 height.


他们刚刚添加的维基所以它更清晰!


they just added the wiki so its more clear!

UI部件没有设置自己的大小和位置。相反,父窗口部件设置的大小和每个孩子的位置。窗口小部件提供了一个最小的,preferred,和最高父可以作为提示使用尺寸。有些家长控件,​​如表,可以给定约束如何大小和位置的孩子们。得到小窗口在布局中的特定大小,小部件的最小值,preferred,并且最大尺寸是左单独和尺寸约束在父集。

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.

布局在维基

希望这可以帮助你解决一些问题了。
问候

Hope it may helps you to fix some issues too.
Regards

这篇关于滑块始终有默认宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆