嗨,我想做这样的事情:
我有文本,我希望文本始终从右向左移动。我想将移动文本的边界设置为 Pane 边界。现在我有了这个,但它没有按照我想要的方式工作
public static void start(Text msg) {
msg.setTextOrigin(VPos.TOP);
double sceneWidth = Config.xSize;
double msgWidth = msg.getLayoutBounds().getWidth();
KeyValue initKeyValue = new KeyValue(msg.translateXProperty(), sceneWidth);
KeyFrame initFrame = new KeyFrame(Duration.ZERO, initKeyValue);
KeyValue endKeyValue = new KeyValue(msg.translateXProperty(), -1.0
* msgWidth);
KeyFrame endFrame = new KeyFrame(Duration.seconds(50), endKeyValue);
Timeline timeline = new Timeline(initFrame, endFrame);
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.play();
我想在我的应用程序中从右到左放置幻灯片文本
最佳答案
您不需要将 KeyValue endKeyValue
和 KeyFrame endFrame
--> 删除它们。在 timeline.play();
之前添加 timeline.setAutoReverse(true);
。
时间轴时间轴 = new Timeline(initFrame, endFrame);
--> 时间轴时间轴 = new Timeline(initFrame);
希望我能帮助你。
编辑:
将 initFrame
的持续时间更改为 Duration.seconds(50)
或其他值。
关于JavaFx文本移动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39571550/