簡體   English   中英

如何將ImageView錨定到其BorderPane區域的中心?

[英]How can I anchor an ImageView to the center of its BorderPane area?

我有一個帶ImageView的BorderPane布局,如下所示,但是ImageView始終固定在左上角,並在調整窗口大小時停留在該位置。 我想讓ImageView保持錨定在它綁定到的部分的中心(紅色框)。 使用FXML是否可能?

在此處輸入圖片說明

FXML:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.Group?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.*?>

<VBox prefWidth="800.0" prefHeight="600.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1">

    <BorderPane xmlns:fx="http://javafx.com/fxml" VBox.vgrow="ALWAYS">
        <top>
            <VBox alignment="TOP_CENTER">
                <ToolBar minHeight="50.0" prefHeight="50.0" prefWidth="800.0" stylesheets="@../css/style.css"
                         GridPane.rowIndex="1">
                    <ImageView fitHeight="35.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
                        <Image url="@../images/toolbar-logo.png"/>
                    </ImageView>
                </ToolBar>
                <MenuBar fx:id="menuBar" prefHeight="0.0" prefWidth="0.0"/>
            </VBox>
        </top>

        <left>
            <StackPane prefWidth="230.0" prefHeight="800.0">
                <ListView fx:id="listView"/>
            </StackPane>
        </left>

        <center>
            <StackPane>
                <ScrollPane>
                    <Group fx:id="selectionGroup">
                        <ImageView fx:id="mainImageView"/>
                    </Group>
                </ScrollPane>
            </StackPane>
        </center>

        <right>
            <TextField promptText="Text"  />
        </right>
    </BorderPane>

</VBox>

更改:

        <StackPane>
            <ScrollPane>
                <Group fx:id="selectionGroup">
                    <ImageView fx:id="mainImageView"/>
                </Group>
            </ScrollPane>
        </StackPane>

至:

        <StackPane>
            <children>
                <ImageView fx:id="mainImageView" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />                    
            </children>
        </StackPane>

您可能需要調整fitWidthfitHeight屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM