我想让JavaFX MediaView拉伸以填充父容器。如何使JavaFX MediaView拉伸媒体填充父项?
我试图从谷歌的一些方法之前,但没有帮助的(也许我是不适用是正确的),并有同名的这个问题,但这个问题的解决方案也许不适合我。
首先我用ahchorpane锚mediaview却发现它不能mediaview舒展了,我不知道为什么,因为像按钮其他控件可以工作。
然后我尝试它的宽度和高度结合anchorpane(mediaview的母公司)
Region region=(Region) mediaplayer.getParent();
mediaplayer.setPreserveRatio(false);
mediaplayer.fitWidthProperty().bind(region.widthProperty());
mediaplayer.fitHeightProperty().bind(region.heightProperty());
它可以扩大mediaview什么时候我调整窗口,但不能缩小下来! 我想这可能是因为区域的大小取决于它的孩子?
最后,我尝试绑定mediaview'size到stage'size,它的工作,但代码看起来很丑,因为我需要计算尺寸manully。
mediaplayer.setPreserveRatio(false);
mediaplayer.fitWidthProperty().bind(stage.widthProperty().subtract(200));
mediaplayer.fitHeightProperty().bind(stage.heightProperty().subtract(135));
有没有更好的解决方案?
不要使用AnchorPane了点。将您的MediaView放在BorderPane的中心。 – VGR