在JavaFX中检测android:weight
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在JavaFX中检测android:weight,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1613字,纯文字阅读大概需要3分钟。
内容图文
我正在开发一个用于JavaFX培训的小软件.
在Android中,在LinearLayout内部,我可以通过设置变量android:weight =“someValue”来扩展视图以填充整个可用空间,遗憾的是我无法实现这是JavaFX.
我试过使用max / min / pref高度,但它不起作用.
任何帮助将非常感激.
解决方法:
使用VBox / HBox,您可以将子节点(或其中一些节点)的vgrow / hgrow静态属性设置为Priority.ALWAYS,这使得父节点增长时这些节点会增长(假设它们可以调整大小).
private static Region createRegion(String color) {
Region region = new Region();
region.setStyle("-fx-background-color: "+color);
return region;
}
@Override
public void start(Stage primaryStage) {
VBox vbox = new VBox(
createRegion("red"),
createRegion("blue"),
createRegion("green")
);
for (Node n : vbox.getChildren()) {
VBox.setVgrow(n, Priority.ALWAYS);
}
Scene scene = new Scene(vbox);
primaryStage.setScene(scene);
primaryStage.show();
}
要控制子项的相对权重,可以使用GridPane,并设置ColumnConstraints / RowConstraints的percentWidth / percentHeight属性.
@Override
public void start(Stage primaryStage) throws IOException {
GridPane root = new GridPane();
root.getColumnConstraints().addAll(DoubleStream.of(30, 2, 68)
.mapToObj(width -> {
ColumnConstraints constraints = new ColumnConstraints();
constraints.setPercentWidth(width);
constraints.setFillWidth(true);
return constraints;
}).toArray(ColumnConstraints[]::new));
RowConstraints rowConstraints = new RowConstraints();
rowConstraints.setVgrow(Priority.ALWAYS);
root.getRowConstraints().add(rowConstraints);
root.addRow(0, Stream.of("red", "green", "blue").map(s -> createRegion(s)).toArray(Node[]::new));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
内容总结
以上是互联网集市为您收集整理的在JavaFX中检测android:weight全部内容,希望文章能够帮你解决在JavaFX中检测android:weight所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。