1

我在 JavaFX SceneBuilder 中的布局有问题。

我有一个GridPane,其中一个单元格包含一个ImageView内部AnchorPane,并希望图像调整为锚点。

我试过这个,但它不起作用。仅以全尺寸显示图像。

        <AnchorPane fx:id="imageAnchor" GridPane.columnIndex="4" GridPane.rowIndex="1">
            <ImageView pickOnBounds="true" fitHeight="${imageAnchor.height}">
            <image>
                <Image url="https: / /www.mydomain.com/path/image.png" />
            </image>
            </ImageView>
        </AnchorPane>

我也试过

        <AnchorPane fx:id="imageAnchor" GridPane.columnIndex="4" GridPane.rowIndex="1">
            <ImageView pickOnBounds="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
            <image>
                <Image url="https: / /www.mydomain.com/path/image.png" />
            </image>
            </ImageView>
        </AnchorPane>

...但两者都不起作用。任何想法可能是什么问题?

我想通过 SceneBuilder / XML 来实现这一点。

4

1 回答 1

1

我最终使用以下方法解决了这个问题:

         <AnchorPane fx:id="imageAnchor" GridPane.columnIndex="1" GridPane.rowIndex="1">
             <ImageView fitHeight="${imageAnchor.height}" managed="false" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                 <image>
                     <Image url="image.png" />
                 </image>
             </ImageView>
         </AnchorPane>
于 2018-04-17T09:40:11.833 回答