首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tripleplay Button:在图像按钮上对齐的动态文本(例如文本对齐,中心)

Tripleplay Button:在图像按钮上对齐的动态文本(例如文本对齐,中心)
EN

Stack Overflow用户
提问于 2012-03-29 13:44:14
回答 1查看 516关注 0票数 1

我正在创建一个带有两个图像按钮的窗口(在我的TriplePlay游戏中使用playN )。

现在我需要这些按钮上的动态文本。但是当我添加带有图像的按钮(setIcon)时,我不能同时在上面添加文本。请检查下面我现在使用的代码块。

代码语言:javascript
复制
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);

在这里,我尝试创建一个根,然后添加带有图像的按钮,然后创建另一个根,并在上面添加标签,这样它就会像图像按钮上的文本一样显示出来。但我知道这是一种不好的做法,而调整将不会根据需要,因为它是一个动态的文本。是否要添加一个按钮,上面有图像和标签?

期待中的感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-30 15:29:04

创建一个带有文本和图标的按钮非常简单:

代码语言:javascript
复制
Button button = new Button("Text").setIcon(iconImage);

然后,您可以随时更改按钮上的文本,如下所示:

代码语言:javascript
复制
button.text.update("New Text");

如果您想要在背景上呈现文本的背景图像按钮,请执行以下操作:

代码语言:javascript
复制
Button button = new Button("Text").
  addStyles(Background.is(Background.image(bgImage)));

请注意,您需要使用最新的TriplePlay代码(来自Github)才能使用ImageBackground。最新的代码还支持Flash风格的"scale9“背景:

代码语言:javascript
复制
Button button = new Button("Text").
  addStyles(Background.is(Background.scale9(bgImage)));
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9926615

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档