[UPDATE] Zauważyłem, że unieważnienie() byłoby dobre, ale nie zmieniło czegoś! Wrzuciłem więc całą gamelayout wraz z utworzeniem tabeli i suwakiem + etykietami. Backbutton jest po prostu tekstem dodanym do końca tabeli. Wiem, że to długi kod, ale wydaje mi się potrzebny.
suwak ma zawsze domyślną szerokość
stworzyłem suwak tak jak wiem, że min szerokość tle służy do szerokości suwaka:
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);
}
To wewnątrz tabeli bez szerokości lub takie. Już przyjrzał jeśli szerokość jest brukowana i jeśli kalkulacja dla prefWidth suwaka bierze moich 600.
Math.max(style.knob == null ? 0 : style.knob.getMinWidth(), style.background.getMinWidth())
jest obliczenie dla szerokości suwaka wewnątrz Sliderclass. Jeśli to obliczyć i zalogować, otrzymam 600.
Wszystko wydaje mi się właściwe, ale suwak jest na tyle mały, że ustawi się na 600.
Tło i gałki są 24x24.
Mam nadzieję, że wy możecie mi powiedzieć, co robię źle.