Mat*_*ari 1 java javafx javafx-2 javafx-8
我ImageView
想在其中一张一张地显示两张图像。我希望这两个图像之间的过渡具有淡入淡出效果。这是我尝试过的:
KeyFrame keyFrame1On = new KeyFrame(Duration.seconds(.2), new KeyValue(imageView.imageProperty(), image1, Interpolator.EASE_OUT));
KeyFrame keyFrame2On = new KeyFrame(Duration.seconds(.5), new KeyValue(imageView.imageProperty(), image2, Interpolator.EASE_OUT));
Timeline timelineOn = new Timeline(keyFrame1On, keyFrame2On);
timelineOn.setAutoReverse(false);
timelineOn.play();
Run Code Online (Sandbox Code Playgroud)
但图像之间的过渡是坚实的,没有褪色。我究竟做错了什么?
插值器实际上并没有为您做任何事情(它只是定义实际时间和用于计算正在更改的属性值的参数之间的映射)。
要实现淡入/淡出,您需要实际opacityProperty
操作.imageView
Timeline
尝试类似的东西
KeyFrame keyFrame1On = new KeyFrame(Duration.seconds(0), new KeyValue(imageView.imageProperty(), image1));
KeyFrame startFadeOut = new KeyFrame(Duration.seconds(0.2), new KeyValue(imageView.opacityProperty(), 1.0));
KeyFrame endFadeOut = new KeyFrame(Duration.seconds(0.5), new KeyValue(imageView.opacityProperty(), 0.0));
KeyFrame keyFrame2On = new KeyFrame(Duration.seconds(0.5), new KeyValue(imageView.imageProperty(), image2));
KeyFrame endFadeIn = new KeyFrame(Duration.seconds(0.8), new KeyValue(imageView.opacityProperty(), 1.0));
Timeline timelineOn = new Timeline(keyFrame1On, startFadeOut, endFadeOut, keyFrame2On, endFadeIn);
Run Code Online (Sandbox Code Playgroud)