簡體   English   中英

如何在javafx中使用節點的寬度制作動畫/過渡?

[英]How to make an animation/transition with the width of a node in javafx?

我想用節點的“寬度”制作動畫。

在這種情況下,我的節點是“AnchorPane”。

我嘗試在 javafx 中制作導航抽屜。

有沒有屬性“width Property()”?

new Key Value (node.width Property (), 1, WEB_EASE)

未找到node.widthProperty().getValue( )

我的代碼:

public void changeWidth(final Node node, double width) {
    this.node = node;
    this.timeline = TimelineBuilder.create()
        .keyFrames(
            new KeyFrame(Duration.millis(20),    
                new KeyValue(    going here?   , width, WEB_EASE)
            )
        )
        .build();

    setCycleDuration(Duration.seconds(5));
    setDelay(Duration.seconds(0));
}

具有“不透明度”屬性的示例:

new KeyValue(node.opacityProperty(), 1, WEB_EASE)

我的類 ConfigAnimationViewPane:

public class ConfigAnimationViewPane extends Transition {
    protected static final Interpolator WEB_EASE = Interpolator.EASE_BOTH;
    protected AnchorPane node;
    protected Timeline timeline;
    private boolean oldCache = false;
    private CacheHint oldCacheHint = CacheHint.DEFAULT;
    private final boolean useCache = true;



    /**
     * Called when the animation is starting
     */
    protected void starting() {
        if (useCache) {
            oldCache = node.isCache();
            oldCacheHint = node.getCacheHint();
            node.setCache(true);
            node.setCacheHint(CacheHint.SPEED);
        }
    }

    /**
     * Called when the animation is stopping
     */
    protected void stopping() {
        if (useCache) {
            node.setCache(oldCache);
            node.setCacheHint(oldCacheHint);
        }
    }

    @Override protected void interpolate(double d) {
        timeline.playFrom(Duration.seconds(d));
        timeline.stop();
    }

}

這是小米控制器:

將菜單向左移動(神秘)

LeftTransition leftTransition = new LeftTransition();
                leftTransition.OpenMenu(list1);
                leftTransition.play();

在這里,我想放置我的尺寸“AnchorPane”。 (設置我的“anchorpane”的寬度)

 /*ViewPaneTransition paneTransition = new ViewPaneTransition();
            paneTransition.CloseMenu(viewPane, width );
            paneTransition.play();*/

這是 java 9 的一個工作示例。它改變了寬度和高度(如果不需要,只需刪除高度線)

widthProperty 是只讀的,因此您必須根據需要設置 maxWidth 或 minWidth 開關。 時間軸上的延遲時長默認為0,無需設置,循環時長由關鍵幀時長計算。

public void changeSize(final Pane pane, double width, double height) {
    Duration cycleDuration = Duration.millis(500);
    Timeline timeline = new Timeline(
            new KeyFrame(cycleDuration,
                    new KeyValue(pane.maxWidthProperty(),width,Interpolator.EASE_BOTH)),
            new KeyFrame(cycleDuration,
                    new KeyValue(pane.maxHeightProperty(),height,Interpolator.EASE_BOTH))
            );

    timeline.play();
    timeline.setOnFinished(event->{
       /* insert code here if you need */
    });
}
public void changeWidth(final Pane/*Region*/ node, double width) {//its a Pane or Regions
    this.node = node;
    this.timeline = TimelineBuilder.create()
        .keyFrames(
            new KeyFrame(Duration.millis(20),    
                new KeyValue(    going here?   , width, WEB_EASE)
            )
        )
        .build();

    setCycleDuration(Duration.seconds(5));
    setDelay(Duration.seconds(0));
}

在這種情況下,我的節點是“AnchorPane”。

你的AnchorPane是一個子類或Pane ,讓你的包裝器或方法接受Pane或它們各自的類

暫無
暫無

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

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