区域表面存在大量的ImagePanels。我把它们分成几个组。它们应该水平滚动在链中。在这里输入图像描述
我写了一些方法让它起作用。在左边切换位置。(长方形)以前是矩形)。
//--------- OO<->OO OOOOOO OOOO -----------------------
private void shiftAnimatedInLeft(ObservableList rects)
{
ParallelTransition pt = new ParallelTransition();
for (int i = 0; i < rects.size(); i++)
{
double startPosition = ((ImagePanel) rects.get(i)).getTranslateX();
double finishPosition = -(rects
.size() - i) * getSideImageOffset() - getCenterOffset() - (IMAGE_WIDTH * (1 - SCALE_SMALL) / 2);
Timeline timeline = new Timeline();
timeline.getKeyFrames().addAll(
new KeyFrame(new Duration(0),
new KeyValue(((ImagePanel) rects.get(i)).translateXProperty(),
startPosition,
INTERPOLATOR)),
new KeyFrame(new Duration(500),
new KeyValue(((ImagePanel) rects.get(i)).translateXProperty(),
finishPosition,
INTERPOLATOR))
);
pt.getChildren().add(timeline);
// timeline.play();
}
pt.play();
}例如,将元素从中间移到左边。
//--------- OOOO <-OOOOOO OOOO -----------------------
private void shiftAnimatedCenterToLeft(ImagePanel rect)
{
double startPosition = rect.getTranslateX();
double finishPosition = - getSideImageOffset() - getCenterOffset() - (IMAGE_WIDTH*(1-SCALE_SMALL)/2);
Timeline timeline = new Timeline();
timeline.getKeyFrames().addAll(
new KeyFrame(new Duration(0),
new KeyValue(rect.translateXProperty(), startPosition, INTERPOLATOR),
new KeyValue(rect.scaleXProperty(), rect.getScaleX(), INTERPOLATOR),
new KeyValue(rect.scaleYProperty(), rect.getScaleY(), INTERPOLATOR),
new KeyValue(rect.angle, -270.0, INTERPOLATOR),
new KeyValue(rect.opacity, 1.0, INTERPOLATOR),
new KeyValue(rect.vboxStyle, "imagePanelBlackVBox", INTERPOLATOR)),
new KeyFrame(new Duration(500),
new KeyValue(rect.translateXProperty(), finishPosition, INTERPOLATOR),
new KeyValue(rect.scaleXProperty(), SCALE_SMALL, INTERPOLATOR),
new KeyValue(rect.scaleYProperty(), SCALE_SMALL, INTERPOLATOR),
new KeyValue(rect.angle, ANGLE, INTERPOLATOR),
new KeyValue(rect.opacity, 0.0, INTERPOLATOR),
new KeyValue(rect.vboxStyle, "imagePanelWhiteVBox", INTERPOLATOR))
);
timeline.play();
}等。
这些方法使用onKeyPressed (左\右)或鼠标滚轮滚动事件。
最后,问题:--如果我尝试在一个独立的应用程序中使用它,它正常工作(但不是很好)。然而,如果我试图将它集成到另一个应用程序中,它就会变得非常滞后,并减缓整个动画的速度。
发布于 2017-03-13 09:58:01
您可以使用Platform.runLater()在另一个线程中运行动画--也许这会有所帮助--或者使用JProfiler(或其他任何免费的等价物)之类的分析器测试应用程序的性能,并优化代码中要求最高的部分。
https://stackoverflow.com/questions/42717610
复制相似问题