我注意到有时内容窗格在初始化后会改变其大小,并且想知道为什么会这样。
这里有一些代码可以在模拟器中演示这一点 - 在模拟器中运行并观察输出 - 较小的皮肤有较小的差异:
public class FormScrollExtras extends Form {
private int entrytally = 0;
private Runnable runnableLog = null;
public FormScrollExtras() {
setTitle("FormScrollExtras");
setScrollable(false);
setTensileDragEnabled(false);
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
contentPane.setScrollableY(true);
contentPane.setTensileDragEnabled(false);
TextArea textArea = new TextArea("This form logs the content panes height and layoutHeight - right after init and whenever an entry is created.");
textArea.setEditable(false);
contentPane.add(textArea);
FloatingActionButton floatingActionButton = FloatingActionButton.createFAB(FontImage2.MATERIAL_ADD);
floatingActionButton.bindFabToContainer(getContentPane(), Component.RIGHT, Component.BOTTOM);
floatingActionButton.addActionListener((e) -> newEntry(contentPane));
contentPane.getParent().layoutContainer(); // Doesn't make a difference
runnableLog = () -> {
Log.p("x/y, height/layoutHeight: " +
contentPane.getAbsoluteX() + "/" + contentPane.getAbsoluteY() + ", " +
contentPane.getHeight() + "/" + contentPane.getLayoutHeight());
};
runnableLog.run();
}
private void newEntry(Container contentPane) {
contentPane.add(new Label("" + ++entrytally));
runnableLog.run();
contentPane.repaint();
}
}
答案 0 :(得分:0)
如果没有与高度变化相关的数字,很难猜测,但您可以通过查看这是仅针对iOS外观还是仅适用于Android外观来验证这一点。
我猜这是因为iOS中保留的状态栏空间会影响工具栏的高度。请注意,在施工期间,元素尚未布局,因此在此阶段没有尺寸保证。有几个回调更具确定性,例如initComponent()
或laidOut()
。