【问题标题】:Codename One - resizing master/detail layout代号一 - 调整主/细节布局
【发布时间】:2020-10-12 04:47:31
【问题描述】:

我的 Android 应用有一个特殊的主/详细表单布局:横向模式下左侧的列表必须与纵向模式下一样大。

我正在移植代号为 One 的应用程序。

这是我在 mainForm 代码中的内容:

if(isTablet() && !isPortrait()) {

        itemListContainer.setWidth(Display.getInstance().getDisplayHeight());
        editingContainer.setWidth(Display.getInstance().getDisplayWidth()-Display.getInstance().getDisplayHeight());
        
        System.out.println("size "+itemListContainer.getWidth()+" "+itemListContainer.getHeight()); 
        //width was 0, now it is 1536 but the actual layout is the same as before, height is 0
//calls to animate() were here but useless
        
        mainForm.add(itemListContainer).add( editingContainer);
      } else {
      
        mainForm.add(itemListContainer);
        
    }
    

我也尝试调用 animate() 方法。

mainForm布局为BoxLayout.x(),即水平。

上面的代码对大小或布局没有影响。我在模拟器上得到了相同的布局,左边的容器有我放在里面的标签的大小。

调整大小的正确方法是什么?

【问题讨论】:

    标签: java swing width codenameone boxlayout


    【解决方案1】:

    使用setPreferredW(int)setWidth 将被布局覆盖,但首选宽度将通过更新/旋转等保持不变。

    请注意,首选尺寸方法已被弃用,因为大多数情况下不鼓励使用它们。更好的方法是使用在这种情况下可能不适用的布局。例如。表格布局支持放置具有宽度百分比约束的组件,这适用于大多数此类用例。

    弃用只是为了提醒您注意这一点,此 API 不会消失或停止工作...

    【讨论】:

      猜你喜欢
      • 2020-09-21
      • 2013-09-18
      • 1970-01-01
      • 2020-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      相关资源
      最近更新 更多