Animation 如何达到缩小图片的效果?
我想隐藏JavaFX应用程序舞台上的一张图片。我想让它收缩消失 让我们说有一些:Animation 如何达到缩小图片的效果?,animation,javafx,Animation,Javafx,我想隐藏JavaFX应用程序舞台上的一张图片。我想让它收缩消失 让我们说有一些: @FXML private ImageView iv; private Image img = new Image(...); 实际img大小为100x100像素 然后 接下来我制作了这样的方法: private Timeline shrink(ImageView iv) { final Timeline animation = new Timeline(); ani
@FXML
private ImageView iv;
private Image img = new Image(...);
实际img
大小为100x100像素
然后
接下来我制作了这样的方法:
private Timeline shrink(ImageView iv)
{
final Timeline animation = new Timeline();
animation.getKeyFrames().addAll(
new KeyFrame(Duration.ZERO,
new KeyValue(iv.fitWidthProperty(), 50)
),
new KeyFrame(Duration.millis(400),
new KeyValue(iv.fitWidthProperty(), 0)
)
);
animation.setCycleCount(1);
animation.play();
}
因此,在那之后,图片正在缩小,但它没有保持0宽度,更糟糕的是,它再次以其原始大小显示:100
我该怎么做才能保持收缩?我不想通过设置Visibile来隐藏它,因为我以后需要额外的空间来填充一些文本。好的,我的错
0
为默认值,因此图片显示为原始大小。例如,需要将其设置为0.01
,然后可能将可见性设置为false。但我相信有更好更好的方法来实现这一点。取决于父布局的预期效果和转换的预期轴心点。。。
private Timeline shrink(ImageView iv)
{
final Timeline animation = new Timeline();
animation.getKeyFrames().addAll(
new KeyFrame(Duration.ZERO,
new KeyValue(iv.fitWidthProperty(), 50)
),
new KeyFrame(Duration.millis(400),
new KeyValue(iv.fitWidthProperty(), 0)
)
);
animation.setCycleCount(1);
animation.play();
}