4

我是 ext JS 的新手,我正在尝试将 3 个组件放在 FormPanel 中,但我不知道如何将它们对齐在中心。

这是我的代码

var durationForm = new Ext.FormPanel({
        border      : false,
        labelAlign  : 'top',
        frame       : true,
        bodyStyle   : 'padding-left:475px;',
        items: [{
          items: [{
            rowWidth    : .5,
            layout      :'column',
                items:[{
                    columnWidth     : .13,
                    layout          : 'form',
                    items           : [getNewLabel('<br/><font size="3">Duration: </font>')]
                },{
                    columnWidth     : .20,
                    layout          : 'form',
                    items           : [fromDate()]
                },{
                    columnWidth     : .17,
                    layout          : 'form',
                    items           : [toDate()]
                }]
          }]
        }]
    });

    durationForm.render(Ext.getBody());

这显示了这样的输出 在此处输入图像描述

但我希望组件在面板的中心对齐。有人知道该怎么做吗?

4

3 回答 3

6

我已经通过使用“表格”布局解决了这个问题:

{
    layout : 'fit', // parent panel should have 'fit' layout 
    items : [ // and only one item
        {
            xtype : 'panel',
            border : false, // optional
            layout : {
                type : 'table',
                columns : 1, 
                tableAttrs : {
                    style : {
                        width : '100%',
                        height : '100%'                                 
                    }
                },
                tdAttrs : {
                    align : 'center',
                    valign : 'middle',
                },
            },
            items : [ // a single container for nested components
                {
                    xtype : 'panel',
                    layout : 'fit',
                    cellId : 'cell_id', // this one will be placed as id for TD
                    items : [
                         {}, {}, {} // nested components
                    ]
                }
            ]
        }
    ]
}
于 2013-06-10T21:21:39.527 回答
3

万一有人像我一样寻找答案但在这里找不到,请在每个项目之间使用 xtype:'splitter' 像这样-

items:[{
         xtype:'something'
       },
       {
         xtype:'splitter'
        },
       {
         xtype:'something-else'
       }
}]
于 2012-10-19T14:53:37.637 回答
2

{
//...
  layout:'hbox',
  layoutConfig: {
    padding:'5',
    pack:'center',
    align:'middle'
  },
  items:[{
       columnWidth     : .13,
       layout          : 'form',
       items           : [getNewLabel(...)]
     },{
       columnWidth     : .20,
       layout          : 'form',
       items           : [fromDate()]
     },{
       columnWidth     : .17,
       layout          : 'form',
       items           : [toDate()]
  }]
//...
}

看到这个

于 2011-07-06T21:58:11.983 回答