【问题标题】:How to make another ImageButton appear when hovering over ImageButton将鼠标悬停在 ImageButton 上时如何使另一个 ImageButton 出现
【发布时间】:2019-06-18 15:16:49
【问题描述】:

如果我将鼠标悬停在一个图像按钮上,我怎样才能使另一个图像按钮出现在该图像按钮上,当你将鼠标移到外面时,它会返回到第一个图像按钮?我已经尝试了很多组合,但到目前为止还没有。

到目前为止我已经尝试过

ImageButton(Drawable imageUp,
                Drawable imageDown,
                   Drawable imageChecked)

但是 setChecked(boolean isChecked) 不适用于此方法,当使用 focusListener 时,当您将鼠标悬停在 ImageButton 上方时,它会将 ImageButton 变成另一个 ImageButton,但当您离开 ImageButton 时,它不会返回到其第一阶段。有任何帮助。

【问题讨论】:

    标签: libgdx imagebutton


    【解决方案1】:

    不要使用imageDown,而是使用imageOver

    据我了解:

    • imageUp
      默认按钮
    • imageOver
      当鼠标/焦点在按钮上时
    • imageDown
      按下按钮时(单击鼠标)
    • imageChecked
      当按钮状态为checked
    • imageCheckedOver
      当按钮的状态为 checked 并且鼠标/焦点位于按钮上方时
    • imageDisabled
      当按钮状态为disabled

    您可以为此使用 ImageButtonStyle。将其传递给按钮的构造函数或使用适当的设置器。

    ImageButtonStylestyle = new ImageButtonStyle();
    style.imageUp = imageUp;
    style.imageOver = imageDown;
    style.imageChecked = imageChecked;
    
    

    附言: 我假设您并不想更改按钮,只是更改显示的图像。

    【讨论】:

    • 我已经尝试过 style.imageOver,但是当将鼠标悬停在 imagebutton 上时,它并没有达到预期的效果。当我们将侦听器添加到按钮时,最好的悬停方法是什么,我假设它是 FocusListener?
    • 另外一件奇怪的事情是,当我点击 imagebutton 时,尽管 ImageButtonStyle 中没有 imageDown,但它仍然会变成另一个 imagebutton。
    • 没关系,你找到了解决方案,我忘了在渲染方法中添加 stage.act()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    • 2020-12-06
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多