简体   繁体   English

Javafx 将 ImageView 调整为 AnchorPane

[英]Javafx resize ImageView to AnchorPane

I have an ImageView inside an AnchorPane and I want to resize the Image in the same proposition as the AnchorPane resize.我在 AnchorPane 中有一个 ImageView,我想按照与 AnchorPane 调整大小相同的命题调整图像大小。

Can someone explain me how to do that?有人可以解释我该怎么做吗?

Many thanks in advance.提前谢谢了。

You can bind the image view's fitWidth and fitHeight properties to the width and height of the anchor pane:您可以将图像视图的fitWidthfitHeight属性绑定到锚点窗格的宽度和高度:

imageView.fitWidthProperty().bind(anchorPane.widthProperty());
imageView.fitHeightProperty().bind(anchorPane.heightProperty());

If you also want to preserve the proportions of the image you are displaying, you can do如果您还想保留正在显示的图像的比例,您可以这样做

imageView.setPreserveRatio(true);

Only thing work for me.唯一对我有用的东西。 On the view, listen change of the AnchorPane and set ImageView Size在视图上,监听 AnchorPane 的变化并设置 ImageView Size

init {
   myAnchorPane.widthProperty().addListener { observable, oldValue, newValue ->
            myImageView.fitWidth = myAnchorPane.width
            myImageView.fitHeight = 0.0
    }
}

See this answer .看到这个答案 Basically you can use the ImageViewPane that you can include in your project.基本上,您可以使用可以包含在项目中的ImageViewPane

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM