Javafx 2 设置JavaFX ImageView的最大大小
我根据场景调整图像视图的大小,但即使场景大于图像原始大小,图像也会继续调整大小 我已经设置了Javafx 2 设置JavaFX ImageView的最大大小,javafx-2,javafx-8,Javafx 2,Javafx 8,我根据场景调整图像视图的大小,但即使场景大于图像原始大小,图像也会继续调整大小 我已经设置了ImageView.maxWidth(originalImageWidth),但它不起作用 我通过将ImageView的大小绑定到场景大小来调整它的大小。这会起作用 Pane root = new VBox(); //or other Pane sub-class ImageView bg = new ImageView(...); bg.setPreserveRatio(false); bg.fitWi
ImageView.maxWidth(originalImageWidth)
,但它不起作用
我通过将ImageView的大小绑定到场景大小来调整它的大小。这会起作用
Pane root = new VBox(); //or other Pane sub-class
ImageView bg = new ImageView(...);
bg.setPreserveRatio(false);
bg.fitWidthProperty().bind(root.widthProperty());
bg.fitHeightProperty().bind(root.heightProperty());
root.getChildren().addAll(bg);
可能不再那么重要了,但我找到了一个至少适合我的解决方案:
- 将setPreserveRatio设置为true
- 将fitHeight设置为所需的最大宽度*比率
- 将fitWidthProperty绑定到screnes widthProperty
换句话说:您可以同时绑定一个维度,并使另一个维度具有最大的配合大小。我也这样做,而且效果很好。我认为,不要使用阶段,而应该使用图像视图的父窗格,如锚定pane@AnshulParashar我正在使用stackpane作为图像视图的父对象,但它不起作用。