LibGDX - ImageTextButton - 对齐
LibGDX - ImageTextButton - Alignment
我在 LibGDX 中创建了一个 ImageTextButton:
_rewardedVideo = new Texture(Gdx.files.internal("menus/blue.png"));
_rewardedVideo.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
_rewardedVideoPressed = new Texture(Gdx.files.internal("menus/bluePressed.png"));
_rewardedVideoPressed.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
_symbolRewardedVideo = new Texture(Gdx.files.internal("menus/symbolRewardedVideo.png"));
_symbolRewardedVideo.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
ImageTextButton.ImageTextButtonStyle styleRewardedVideo = new ImageTextButton.ImageTextButtonStyle();
styleRewardedVideo.up = new TextureRegionDrawable(new TextureRegion(_rewardedVideo));
styleRewardedVideo.down = new TextureRegionDrawable(new TextureRegion(_rewardedVideoPressed));
styleRewardedVideo.imageUp = new TextureRegionDrawable(new TextureRegion(_symbolRewardedVideo));
styleRewardedVideo.font = skin.getFont("large-font");
styleRewardedVideo.fontColor = Color.WHITE;
buttonRewardedVideo = new ImageTextButton("WATCH VIDEO", styleRewardedVideo);
buttonRewardedVideo.setPosition(580, 180);
buttonRewardedVideo.setSize(450, 80);
// The last two lines do not work:
buttonRewardedVideo.getLabel().setAlignment(Align.left);
buttonRewardedVideo.getImage().setAlign(Align.right);
我希望该按钮包含左对齐标签和右对齐图像。但事实恰恰相反:
https://i.ibb.co/QCZPqT8/Image-Text-Button.png
出了什么问题,我该如何解决?
ImageTextButton
是 Table
,如果您查看 class,它首先添加 Image
,然后添加 Label
...
public ImageTextButton (String text, ImageTextButtonStyle style) {
super(style);
this.style = style;
defaults().space(3);
image = new Image();
image.setScaling(Scaling.fit);
label = new Label(text, new LabelStyle(style.font, style.fontColor));
label.setAlignment(Align.center);
add(image);
add(label);
setStyle(style);
setSize(getPrefWidth(), getPrefHeight());
}
您可以创建自己的 class,它将是 ImageTextButton
的副本,只需交换这些行或清除 table 并像这样重新添加项目。 .
buttonRewardedVideo = new ImageTextButton("WATCH VIDEO", styleRewardedVideo);
buttonRewardedVideo.clearChildren();
buttonRewardedVideo.add(buttonRewardedVideo.getLabel());
buttonRewardedVideo.add(buttonRewardedVideo.getImage());
buttonRewardedVideo.setPosition(580, 180);
buttonRewardedVideo.setSize(450, 80);
我在 LibGDX 中创建了一个 ImageTextButton:
_rewardedVideo = new Texture(Gdx.files.internal("menus/blue.png"));
_rewardedVideo.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
_rewardedVideoPressed = new Texture(Gdx.files.internal("menus/bluePressed.png"));
_rewardedVideoPressed.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
_symbolRewardedVideo = new Texture(Gdx.files.internal("menus/symbolRewardedVideo.png"));
_symbolRewardedVideo.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
ImageTextButton.ImageTextButtonStyle styleRewardedVideo = new ImageTextButton.ImageTextButtonStyle();
styleRewardedVideo.up = new TextureRegionDrawable(new TextureRegion(_rewardedVideo));
styleRewardedVideo.down = new TextureRegionDrawable(new TextureRegion(_rewardedVideoPressed));
styleRewardedVideo.imageUp = new TextureRegionDrawable(new TextureRegion(_symbolRewardedVideo));
styleRewardedVideo.font = skin.getFont("large-font");
styleRewardedVideo.fontColor = Color.WHITE;
buttonRewardedVideo = new ImageTextButton("WATCH VIDEO", styleRewardedVideo);
buttonRewardedVideo.setPosition(580, 180);
buttonRewardedVideo.setSize(450, 80);
// The last two lines do not work:
buttonRewardedVideo.getLabel().setAlignment(Align.left);
buttonRewardedVideo.getImage().setAlign(Align.right);
我希望该按钮包含左对齐标签和右对齐图像。但事实恰恰相反: https://i.ibb.co/QCZPqT8/Image-Text-Button.png
出了什么问题,我该如何解决?
ImageTextButton
是 Table
,如果您查看 class,它首先添加 Image
,然后添加 Label
...
public ImageTextButton (String text, ImageTextButtonStyle style) {
super(style);
this.style = style;
defaults().space(3);
image = new Image();
image.setScaling(Scaling.fit);
label = new Label(text, new LabelStyle(style.font, style.fontColor));
label.setAlignment(Align.center);
add(image);
add(label);
setStyle(style);
setSize(getPrefWidth(), getPrefHeight());
}
您可以创建自己的 class,它将是 ImageTextButton
的副本,只需交换这些行或清除 table 并像这样重新添加项目。 .
buttonRewardedVideo = new ImageTextButton("WATCH VIDEO", styleRewardedVideo);
buttonRewardedVideo.clearChildren();
buttonRewardedVideo.add(buttonRewardedVideo.getLabel());
buttonRewardedVideo.add(buttonRewardedVideo.getImage());
buttonRewardedVideo.setPosition(580, 180);
buttonRewardedVideo.setSize(450, 80);