2016-04-21 7 views
0

Ich benutze eine Animation in javafx, also wenn ich auf den Knopf klicke, bewege ich mich mit einer Animation, aber ich möchte auch die Größe ändern (Es sollte kleiner und kleiner werden).wie man die Größe der Schaltfläche in einer Animation ändert javafx

public class Main extends Application { 

    @Override 
    public void start(Stage primaryStage) throws Exception{ 
     /*Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));*/ 
     AnchorPane root=new AnchorPane(); 
     Timeline timeline = new Timeline(); 
     Button button = new Button(); 



     timeline.getKeyFrames().addAll(
       new KeyFrame(Duration.ZERO, 
         new KeyValue(button.translateXProperty(), 500), 
         new KeyValue(button.translateYProperty(), 500)), 

       new KeyFrame(Duration.seconds(.5), // set end position at 40s 
         new KeyValue(button.translateXProperty(), 200), 
         new KeyValue(button.translateYProperty(), 200))); 



     timeline.play(); 


     root.getChildren().addAll(button); 
     primaryStage.show(); 

     primaryStage.setTitle("Hello World"); 
     primaryStage.setScene(new Scene(root, 800, 800)); 
     primaryStage.show(); 
    } 


    public static void main(String[] args) { 
     launch(args); 
    } 
} 

Antwort

1

Eine Möglichkeit ist, den Knoten des scaleProperties zu animieren:

timeline.getKeyFrames().addAll(
             new KeyFrame(Duration.ZERO, 
                new KeyValue(button.translateXProperty(), 500), 
                new KeyValue(button.translateYProperty(), 500), 
                new KeyValue(button.scaleXProperty(), 1), 
                new KeyValue(button.scaleYProperty(), 1)), 

             new KeyFrame(Duration.seconds(.5), // set end position at 40s 
                new KeyValue(button.translateXProperty(), 200), 
                new KeyValue(button.translateYProperty(), 200), 
                new KeyValue(button.scaleXProperty(), .4), 
                new KeyValue(button.scaleYProperty(), .4))); 

     timeline.play(); 
Verwandte Themen