根据我的理解,ImageButton内部LibGDX是包含图像的框架.是否可以设置框架的背景?
例如,我想使用Button背景,并在该图像的顶部应用一个Icon.
皮肤与背景:
"com.badlogic.gdx.scenes.scene2d.ui.ImageButton$ImageButtonStyle": {
"default": {
"imageDown": "button-down",
"imageUp": "button-up"
}
}
Run Code Online (Sandbox Code Playgroud)
创建ImageButton:
// Getting imageButtonStyle with "default" style, as it just has the background.
ImageButton.ImageButtonStyle imageButtonStyle = skin.get( "default", ImageButton.ImageButtonStyle.class );
ImageButton button = new ImageButton( imageButtonStyle );
// Set the image on the button to something.
Run Code Online (Sandbox Code Playgroud)


谢谢您的帮助.
小智 9
诀窍是使用2种不同的样式.ImageButtonStyle用于设置图标属性,但由于ImageButtonStyle扩展了ButtonStyle,因此背景属性在ButtonStyle中设置.就像是:
ImageButtonStyle style = new ImageButtonStyle();
style.up = background;
style.down = background;
style.checked = background;
style.imageUp = icon_up;
style.imageDown = icon_down;
style.imageChecked = icon_checked;
style.unpressedOffsetY = -20; // to "not" center the icon
style.unpressedOffsetX = -30; // to "not" center the icon
ImageButton heartButton = new ImageButton(style);
ImageButton envelopeButton = new ImageButton(envelopeStyle);
Run Code Online (Sandbox Code Playgroud)
这样的东西(对我来说,背景,icon_*都是Drawable).但这是基础知识,对我来说就像一个魅力.
| 归档时间: |
|
| 查看次数: |
8665 次 |
| 最近记录: |