我想创建一个RippleAnimation
,因此我创建了一个圆圈并使用ScaleTransition
并使用Button
setGraphic(..);
示例代码:
final Circle circle = new Circle(3);
circle.setFill(Color.color(0, 0, 0, 0.2));
ScaleTransition scaleTransition = new ScaleTransition(Duration.millis(500), circle);
scaleTransition.setToX(50f);
scaleTransition.setToY(50f);
scaleTransition.setAutoReverse(false);
scaleTransition.setCycleCount(1);
button.setGraphic(circle);
button.setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
scaleTransition.play();
}
});
...
但它超越了Button
:
如何实现圈子不会越过按钮?
答案 0 :(得分:1)
只需使用形状裁剪:
Rectangle clip = new Rectangle();
clip.widthProperty().bind(button.widthProperty());
clip.heightPropety().bind(button.heightProperty());
circle.setClip(clip);
希望这有效,导致避难所曾与setGraphics()
合作过。也许尝试将按钮+圆圈放入StackPane
以获得相同的结果。