`

布局管理(一)

 
阅读更多

 

5.1ExtJS的布局管理器及其继承关系


从图中可以看出:Ext.layout.ContainerLayoutExtJS所有布局类的根,它也是容器组件的缺省布局类:在容器中一个接一个地安排组件的显示,通常也称它为流式布局。一个使用Ext.layout.ContainerLayout布局的简单例子:

 

var childPnl1 = {
   frame  : true,
   height : 50,
   html   : 'My First Child Panel',
   title  : 'First children are fun'
}
var childPnl2 = {
   xtype  : 'panel',
   width  : 150,
   html   : 'Second child',
   title  : 'Second children have all the fun!'
}
var myWin = new Ext.Window({
   height     : 300,
   width      : 300,
   title      : 'A window with a container layout',
   autoScroll : true,
   items      : [
      childPnl1,
      childPnl2
   ],
   tbar : [
      {
         text    : 'Add child',
         handler : function() {
            var numItems = myWin.items.getCount() + 1;
            myWin.add({
               title       : 'Child number ' + numItems,
               height      : 60,
               frame       : true,
               collapsible : true,
               collapsed   : true,
               html        : 'Yay, another child!'
            });
            myWin.doLayout();
         }
      }
   ]
});
myWin.show();
 

运行结果:




 
 <!--[endif]-->

在对ExtJS的容器进行布局时,使用Ext.Container”layout”属性指定布局管理,使用Ext.Container”layoutConfig”属性来对布局管理器的特定属性进行配置。各个布局管理器可以被配置的属性在ExtJSAPI的各个布局管理器的Config Options中。

5.2Ext.layout.AnchorLayout布局

Ext.layout.AnchorLayout与流式布局类似,只是在使用Ext.layout.AnchorLayout布局时可以在容器的items属性所指定的各个组件中使用:

anchor: “width, height”

来指定各个组件相对于容器的宽度和高度:%及整数类型的值均可以,其中”%”就是子组件相对于容器的百分比,而整数值就是子组件的大小等于容器的大小加上这个整数值。同时,对于使用Ext.layout.AnchorLayout进行布局管理的容器来说,可以在容器的配置属性中使用:

anchorSize: {width:宽度, height:高度},

来指定容器的布局宽度和布局高度,注意,这里的布局宽度和布局高度与容器实际的宽度和高度无关。一个使用Ext.layout.AnchorLayout进行布局的例子:

 

var myWin = new Ext.Window({
         height     : 300,
         width      : 300,
         layout     : 'anchor',
         autoScroll : true,
         border     : false,
         anchorSize : {width:400, height:300},
         items      : [
                   {
                            title  : 'Panel1',
                            anchor : '100%, 25%',
                            frame  : true
                   },
                   {
                            title  : 'Panel2',
                            anchor : ‘100%, 50%',
                            frame  : true
                   },
                   {
                            title  : 'Panel3',
                            anchor : '50%, 25%',
                            frame  : true
                   }
         ]
});
myWin.show();
 

运行结果:





 
 
 <!--[endif]-->

5.4Ext.layout.FormLayout布局

FormLayoutAnchorLayout的子类,因此,AnchorLayout中相关配置属性,例如anchoranchorSize同样适用于FormLayout

使用FormLayout进行布局管理的容器可以在容器配置中使用如下这些FormLayout相关配置属性来对容器进行配置:

  •    hideLabels
  •    labelAlign
  •    labelPad
  •    labelSeparator
  •             labelWidth

这些配置属性的含义不言而喻。同时,对于采用FormLayout进行布局管理的容器,该容器中的组件则可以使用如下的FormLayout相关的属性进行配置:

 

  •        anchor
  •        clearCls
  •        fieldLabel
  •        hideLabel
  •        itemCls
  •        labelSeparator
  •        labelStyle

这些配置属性的含义不言而喻的。一个采用FormLayout布局的例子:

 

var myWin =  new Ext.Window({
         height      : 220,
         width       : 230,
         bodyStyle   : 'padding: 5px',
         layout      : 'form',
         labelWidth  : 50,
         defaultType : 'field',
         items       : [
                   {
                            fieldLabel : 'Name',
                            anchor     : '-4'
                   },
                   {
                            fieldLabel : 'Age',
                            width      : 25
                   },
                   {
                            xtype      : 'combo',
                            fieldLabel : 'Location',
                            anchor     : '-4',
                            store      : [ 'Here', 'There', 'Anywhere' ]
                   },
                   {
                            xtype      : 'textarea',
                            fieldLabel : 'Bio',
                            anchor     : '-4, -135'
                   },
                   {
                            xtype          : 'panel',
                            fieldLabel     : ' ',
                            labelSeparator : '',
                            frame          : true,
                            title          : 'Instructions',
                            html           : 'Please fill in the form',
                            anchor         : '-4',
                   }
    ]
});
myWin.show();
 

运行结果:



5.5Ext.layout.AbsoluteLayout布局

采用绝对位置和大小对组件进行布局。在容器的组件中可以使用”xy”属性来指明组件在容器中的位置,及可以使用”widthheight”属性来指明组件的大小,如此而已。一个例子:

 

var myWin = new Ext.Window({
         height     : 300,
         width      : 300,
         layout     : 'absolute',
         autoScroll : true,
         id         : 'myWin',
         border     : false,
         items      : [
                   {
                            title : 'Panel1',
                            x      : 50,
                            y      : 50,
                            height : 100,
                            width  : 100,
                            html   : 'x: 50, y:100',
                            frame  : true
                   },
                   {
                            title  : 'Panel2',
                            x      : 90,
                            y      : 120,
                            height : 75,
                            width  : 77,
                            html   : 'x: 90, y: 120',
                            frame  : true
                   }
         ]
});
myWin.show();
 

5.6Ext.layout.FitLayout布局

容器的items中只有一个组件,并且这个组件将占据容器的全部显示空间,这就是就是fit布局。fit布局没有为容器或组件添加任何其他的配置属性。一个fit布局的例子:

 

var myWin = new Ext.Window({
         height     : 200,
         width      : 200,
         layout     : 'fit',
         autoScroll : true,
         border     : false,
         items      : [
                   {
                            title : 'Panel1',
                            html   : 'I fit in my parent!',
                            frame  : true
                   }
         ]
});
myWin.show();
 

5.7Ext.layout.AccordionLayout布局

AccordionLayoutFitLayout的直接子类。AccordionLayout布局以垂直堆叠的方式显示组件,并且,在任何一个时刻,只有一个item是展开的。一个AccordionLayout布局的例子:

 

var myWin = new Ext.Window({
         height       : 200,
         width        : 300,
         border       : false,
         title        : 'A Window with an accordion layout',
         layout       : 'accordion',
         layoutConfig : {
                   animate : true
         },
         items : [
                   {
                            xtype       : 'form',
                            title       : 'General info',
                            bodyStyle   : 'padding: 5px',
                            defaultType : 'field',
                            labelWidth  : 50,
                            items       : [
                                     {
                                               fieldLabel : 'Name',
                                               anchor     : '-10',
                                     },
                                     {
                                               xtype      : 'numberfield',
                                               fieldLabel : 'Age',
                                               width      : 30
                                     },
                                     {
                                               xtype      : 'combo',
                                               fieldLabel : 'Location',
                                               anchor     : '-10',
                                               store      : [ 'Here', 'There', 'Anywhere' ]
                                     }
                            ]
                   },
                   {
                            xtype  : 'panel',
                            autoEl : {},
                            title  : 'Bio',
                            layout : 'fit',
                            items  : {
                                     xtype : 'textarea',
                                     value  : 'Tell us about yourself'
                            }
                   },
                   {
                            title : 'Instructions',
                            html  : 'Please enter information.',
                            tools : [
                                     {id : 'gear'}, {id:'help'}
                            ]
                   }
         ]
        
});
myWin.show();
 

运行实例:





 

 

 

 

  • 大小: 24.8 KB
  • 大小: 17.1 KB
  • 大小: 15.2 KB
  • 大小: 19.3 KB
  • 大小: 38.2 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics