【发布时间】:2017-03-10 11:43:47
【问题描述】:
Region 表面上有很多 ImagePanel。我将它们保存在组中。它们应该水平滚动。enter image description here
我为此编写了一些方法。 例如。左侧切换位置。 (rects - 矩形。之前是矩形)。
//--------- 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 (left\right) 或鼠标滚轮滚动事件。
最后,问题:如果我尝试在一个独立的应用程序中使用它,它可以正常工作(但不是很好)。但是,如果我尝试将其集成到另一个应用程序中,这一切都会变得非常滞后并减慢整体动画速度。
【问题讨论】:
标签: animation javafx-8 timeline