我正在创建一个带有两个图像按钮的窗口(在我的TriplePlay游戏中使用playN )。
现在我需要这些按钮上的动态文本。但是当我添加带有图像的按钮(setIcon)时,我不能同时在上面添加文本。请检查下面我现在使用的代码块。
Interface iface = new Interface(null);
pointer().setListener(iface.plistener);
Styles buttonStyles = Styles.none().add(Style.BACKGROUND.is(new NullBackground())).
addSelected(Style.BACKGROUND.is(Background.solid(0xFFCCCCCC)));
Stylesheet rootSheet = Stylesheet.builder().add(Button.class, buttonStyles).create();
Root buttonroot = iface.createRoot(AxisLayout.horizontal().gap(150), rootSheet);
buttonroot.setSize(width_needed, height_needed);
buttonroot.addStyles(Styles.make(Style.BACKGROUND.is(new NullBackground())));
graphics().rootLayer().add(buttonroot.layer);
Button you = new Button().setIcon(buttonImage);
Button friend = new Button().setIcon(buttonImage);
buttonroot.add(you).add(friend);
buttonroot.layer.setTranslation(x_needed, y_needed);
Root nameroot = iface.createRoot(AxisLayout.horizontal().gap(300), rootSheet);
nameroot.setSize(width_needed, height_needed);
nameroot.addStyles(Styles.make(Style.BACKGROUND.is(new NullBackground())));
graphics().rootLayer().add(nameroot.layer);
name = new Label("YOU");// we need the dynamic string variable instead
friendName = new Label("FRIEND"); // we need the dynamic string variable instead
nameroot.add(name).add(friendName);
nameroot.layer.setTranslation(x_needed, y_needed);在这里,我尝试创建一个根,然后添加带有图像的按钮,然后创建另一个根,并在上面添加标签,这样它就会像图像按钮上的文本一样显示出来。但我知道这是一种不好的做法,而调整将不会根据需要,因为它是一个动态的文本。是否要添加一个按钮,上面有图像和标签?
期待中的感谢
发布于 2012-03-30 15:29:04
创建一个带有文本和图标的按钮非常简单:
Button button = new Button("Text").setIcon(iconImage);然后,您可以随时更改按钮上的文本,如下所示:
button.text.update("New Text");如果您想要在背景上呈现文本的背景图像按钮,请执行以下操作:
Button button = new Button("Text").
addStyles(Background.is(Background.image(bgImage)));请注意,您需要使用最新的TriplePlay代码(来自Github)才能使用ImageBackground。最新的代码还支持Flash风格的"scale9“背景:
Button button = new Button("Text").
addStyles(Background.is(Background.scale9(bgImage)));https://stackoverflow.com/questions/9926615
复制相似问题