如何实现水平对齐的按钮列表,一次只能检查一个按钮?我想为一个游戏实现此功能,在该游戏中,您必须从列表中选择工具,然后单击一个对象才能执行操作。我要突出显示代表当前工具的按钮,并且当您选择另一个工具以将前一个工具返回到非突出显示状态时,而已选择的一个则返回突出显示状态。因此,在任何给定的时刻,只有一个工具处于活动状态,并且在您使用该工具并且未选择其他任何东西之后,应该没有突出显示的按钮。我过去两天尝试自己实施,但无法完成。我以为libgdx scene2d中可能有类似的东西,但是我什么也没找到。任何帮助或建议,将不胜感激。
听起来像ButtonGroup的工作。我很惊讶在基本的Google搜索后没有出现。
在此处查看答案:LibGDX:取消选中舞台上的所有演员
//initalize stage and all your buttons
ButtonGroup buttonGroup = new ButtonGroup(button1, button2, button3, etc...)
//next set the max and min amount to be checked
buttonGroup.setMaxCheckCount(1);
buttonGroup.setMinCheckCount(0);
//it may be useful to use this method:
setUncheckLast(true); //If true, when the maximum number of buttons are checked and an additional button is checked, the last button to be checked is unchecked so that the maximum is not exceeded.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句