我试图按顺序显示三个图像,并对每个图像进行一些比例变换(1,2,3的图像)。我在imageview的单个实例上使用ScaleTransition,在每次连续转换后,imageView高度得到缩放,而不是重置 我的代码是
public void start(Stage primaryStage) {
final IntegerProperty intProperty = new SimpleIntegerProperty(0);
final Image[] array = {
(new Image(WaitEffect.class.getResource("1.png")
.toExternalForm())),
(new Image(WaitEffect.class.getResource("2.png")
.toExternalForm())),
(new Image(WaitEffect.class.getResource("3.png")
.toExternalForm())) };
Group root = new Group();
Scene scene = new Scene(root, 400, 400, Color.BLACK);
StackPane pane = StackPaneBuilder.create()
.layoutX(scene.getWidth() / 2).layoutY(scene.getHeight() / 2)
.build();
final ImageView imageView = new ImageView();
pane.getChildren().add(imageView);
Timeline timeline = new Timeline();
int count = 0;
KeyValue value = new KeyValue(intProperty, count++);
KeyFrame frame = new KeyFrame(Duration.millis(2000),
new EventHandler<ActionEvent>() {
int co = 0;
@Override
public void handle(ActionEvent paramT) {
imageView.setImage(array[co]);
ScaleTransition st = ScaleTransitionBuilder.create()
.byX(2).byY(2).node(imageView)
.duration(Duration.millis(500)).build();
st.play();
imageView.setFitHeight(150);
imageView.setFitWidth(150);
imageView.resize(150, 150);
co++;
}
}, value);
timeline.getKeyFrames().add(frame);
timeline.setCycleCount(3);
timeline.play();
root.getChildren().addAll(pane);
primaryStage.setScene(scene);
primaryStage.show();
}`
答案 0 :(得分:2)
ImageView
后, Image
不会重置其属性。您需要自己重置,例如设置from
的{{1}}属性:
ScaleTransition