簡體   English   中英

如何在FadeTransition中添加多個按鈕?

[英]How to add more than one button to a FadeTransition?

我有一個用於學校的程序,試圖創建一個自動售貨機,並且我試圖使多個按鈕成為烘焙對象,以從同一過渡中淡出過渡! 這是否可能,或者每個按鈕是否必須具有完全不同的淡入淡出過渡?

FadeTransition ft = new FadeTransition();
ft.setNode(imgView1);
ft.setDuration(Duration.millis(5000));
ft.setFromValue(1.0);
ft.setToValue(0.0);
ft.setCycleCount(1);
ft.setAutoReverse(true);
ft.plat();

btn1.setOnMousePressed(e->ft.play());

我還有3個其他按鈕和圖像,我想使用它們來做同樣的事情,但是不確定是否必須進行每個Sepedated FadeTransition或是否可以將它們添加到此按鈕中?

除非這些節點是公共父級中唯一沒有視覺效果的節點,否則您不能將過渡應用於多個節點。

但是,您可以將其他節點的opacity屬性綁定到動畫節點的opacity

node2.opacityProperty().bind(imgView1.opacityProperty());
node3.opacityProperty().bind(imgView1.opacityProperty());

您還可以為每個節點創建一個帶有KeyValue元素的Timeline

Timeline timeline = new Timeline(new KeyFrame(Duration.ZERO,
                                              new KeyValue(node1.opacityProperty(), 1d),
                                              new KeyValue(node2.opacityProperty(), 1d),
                                              new KeyValue(node3.opacityProperty(), 1d)),
                                 new KeyFrame(Duration.seconds(5),
                                              new KeyValue(node1.opacityProperty(), 0d),
                                              new KeyValue(node2.opacityProperty(), 0d),
                                              new KeyValue(node3.opacityProperty(), 0d)));

timeline.setAutoReverse(true);
timeline.play();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM