dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to animate a button with Timeline?

  1. #1
    Join Date
    Nov 2018
    Posts
    1

    How to animate a button with Timeline?

    Hello!

    I want to animate a button. I want to make it change its position after clicking on it. I wrote such code, but it does not work. In this case, no errors appear in the console. The button simply does not respond to pressing.

    Code:
    double stopPosition = 100;
    KeyValue kk2 = new KeyValue(btn.layoutXProperty(), stopPosition, Interpolator.LINEAR);
    KeyFrame kk = new KeyFrame(Duration.millis(5000),kk2);
    Timeline timeline = new Timeline();
    timeline.getKeyFrames().add(kk);
    timeline.setCycleCount(1);
            
            btn.setOnAction(new EventHandler<ActionEvent>() {
                
                @Override
                public void handle(ActionEvent event) {
                    System.out.println("Hello World!");
                    timeline.play();
                }
            });
    What am I doing wrong?

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,856

    Re: How to animate a button with Timeline?

    Can you make a small, complete program that compiles, executes and shows the problem?
    Norm

  3. #3
    Join Date
    Dec 2018
    Posts
    8

    Re: How to animate a button with Timeline?

    I think the button in some layout that takes care of positioning. If you modify layoutX this means during the next layout pass the Button is simply put back "where it belongs" by the parent layout.

    If you want to move the Button, you should choose a different layout as parent or use the translateX property instead. translateX moves the Button relative to the position where the parent layout places it (layoutX).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)