[UPDATE] Tôi nhận thấy rằng invalidate() sẽ tốt nhưng nó không thay đổi gì đó! Vì vậy, tôi đặt toàn bộ tùy chọn với việc tạo bảng và nhãn trượt +. Backbutton chỉ là một textbutton được thêm vào cuối bảng. Tôi biết một mã dài của nó nhưng tôi dường như là cần thiết.
thanh trượt luôn có chiều rộng mặc định
tôi đã tạo một thanh trượt như thế này như tôi biết rằng chiều rộng tối thiểu của nền được sử dụng cho chiều rộng thanh trượt:
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);
}
Đó là bên trong một bảng không có chiều rộng hay như vậy. Tôi đã mất một cái nhìn nếu chiều rộng là sett và nếu tính toán cho prefWidth của thanh trượt không lấy tôi 600.
Math.max(style.knob == null ? 0 : style.knob.getMinWidth(), style.background.getMinWidth())
đây là tính toán cho chiều rộng của thanh trượt bên trong Sliderclass. Nếu tôi tính toán và ghi lại nó, tôi có được 600.
Mọi thứ có vẻ đúng với tôi nhưng thanh trượt là cách nhỏ đối với dàn xếp 600 i.
Nền và hình chữ nhật là 24x24.
Vì vậy, tôi hy vọng các bạn có thể cho tôi biết tôi đang làm gì sai.