`

Extjs4.0中hbox用法

阅读更多
要使用HBOX的属性,首先要熟悉一下属性的内容:
一、align:字符类型,表示组件的对齐方式,有如下几种:
1.top(默认):排列与容器顶部
2.middle:垂直居中排列与容器中
3.stretch:垂直排列且拉伸义填补容器高度
4.stretchmax:垂直拉伸,并且组件以最高高度的组件为准
二、flex:数值类型,指示组件在容器中水平呈现方式,通俗的讲,就是指示组件在容器中的相对宽度
三、pack,字符类型,指组件在容器中的位置,有如下几种:
1.start(默认):组件在容器左边
2.center:组件在容器中间
3.end:组件在容器右边
实例代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>component.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=GB18030">
    <!--根据自己工程中的情况设置  -->
    <link rel="stylesheet" type="text/css" href="../../Extjs/resources/css/ext-all.css">
    <script type="text/javascript" src="../../Extjs/bootstrap.js"></script>
 	<script type="text/javascript" src="../../js/window/hbox.js"></script>
  </head>
  
  <body>
    This is my HTML page. <br>
  </body>
  <div id="d1"></div>
  <div id="d2"></div>
  <div id="d3"></div>
</html>



hbox.js文件如下:
  Ext.onReady(function(){
     var d1 = Ext.create('Ext.panel.Panel',{
        title:'HBOX 顶端对齐,且组件在容器的左边',
        frame:true,
        width:600,
        height:100,
        items:[{
            anchor:'100%',
            layout:{
               type:'hbox',
               padding:'10',
               pack:'start',
               align:'top'
            },
            defaults:{
               margins:'0,5,0,0'
            },
            items:[{
               xtype:'button',
               text:'button1'
            },{
               xtype:'button',
               text:'button2'
            },{
               xtype:'button',
               text:'button3'
            },{
               xtype:'button',
               text:'button4'
            }]

        }]
     });
     d1.render('d1');
     var d2 = Ext.create('Ext.panel.Panel',{
        title:'HBOX 垂直对齐,且组件在容器的右边',
        frame:true,
        width:600,
        height:100,
        items:[{
            anchor:'100%',
            layout:{
               type:'hbox',
               padding:'10',
               pack:'end',
               align:'middle'
            },
            defaults:{
               margins:'0,5,0,0'
            },
            items:[{
               xtype:'button',
               text:'button1'
            },{
               xtype:'button',
               text:'button2'
            },{
               xtype:'button',
               text:'button3'
            },{
               xtype:'button',
               text:'button4'
            }]

        }]
     });
     d2.render('d2');
     var d3 = Ext.create('Ext.panel.Panel',{
        title:'HBOX 垂直水平居中,且所有控件的高度为最高控件的高度',
        frame:true,
        width:600,
        height:100,
        items:[{
            anchor:'100%',
            layout:{
               type:'hbox',
               padding:'10',
               pack:'center',
               align:'stretchmax'
            },
            defaults:{
               margins:'0,5,0,0'
            },
            items:[{
               xtype:'button',
               text:'Small size'
            },{
               xtype:'button',
               scale:'medium',
               text:'Middle size'
            },{
               xtype:'button',
               scale:'large',
               text:'Large size'
            }]

        }]
     });
     d3.render('d3');     
  });
  • 大小: 43.2 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics