简体   繁体   中英

Javafx analog for android RelativeLayout

I was working for a while with android and liked useful class RelativeLayout there. It helps to position elements on the screen easily, relative to each other.

Not long ago I've switched to javafx. Sometimes I feel I need this useful class, but I couldn't find any analog. Does anybody knows any way to make fxml layout elements acting similarly?

There's no exact equivalent for this in JavaFX, but there are some layouts that allow you to get similar effects.

GridPane allows you to specify row and column indices for it's children. If the indices of children that are supposed to be placed next to each other differ by 1, they should be placed next to each other. You can also make a child use multiple rows/columns by setting the rowSpan / columnSpan . There are several constraints that influence resizing of the node.

VBox / HBox allow you to place nodes next to each other vertically/horizontally.

AnchorPane allows you to specify distances from the sides where a node should be placed.

Depending on your required constraints a AnchorPane containing (possibly nested) HBox es and VBox es could reproduce the desired layout, but using GridPane , if it works for you, is much simpler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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