ExtJS4学习笔记(三)---VBox的使

要使用VBox布局方式,首先的熟悉下一下几个主要属性:

一、align:字符类型,指示组件在容器内的对齐方式。有如下几种属性。

    1、left(默认):排列于容器左侧。

    2、center :控件在容器水平居中。

    3、stretch:控件横向拉伸至容器大小

    4、stretchmax:控件横向拉伸,宽度为最宽控件的宽。

二、flex:数字类型,指示组件在容器中水平呈现方式,通俗的讲,就是指示组件在容器中的相对宽度。

三、pack : 字符类型,指示组件在容器的位置,有如下几种属性。

    1、start(默认):组件在容器上边

    2、center:组件在容器中间

    3、end:组件在容器的下边

 

HTML代码:

 
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>VBox---MHZG.NET</title>
  6. <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
  7. <script type="text/javascript" src="../../bootstrap.js"></script>
  8. <script type="text/javascript" src="../../locale/ext-lang-zh_CN.js"></script>
  9. <script type="text/javascript" src="vbox.js"></script>
  10. <style type="text/css">
  11.         html, body {
  12.             font: normal 12px verdana;
  13.             margin: 0;
  14.             padding: 0;
  15.             border: 0 none;
  16.         }
  17.     </style>
  18. </head>
  19. <body>
  20. </body>
  21. </html>

vbox.js:

 
  1. Ext.onReady(function() {
  2.             var currentName;
  3.             var replace = function(config, name) {
  4.                 var btns = Ext.getCmp('btns');
  5.                 if (name && name != currentName) {
  6.                     currentName = name;
  7.                     btns.remove(0);
  8.                     btns.add(Ext.apply(config));
  9.                 }
  10.             };
  11.              
  12.             var viewport = Ext.create('Ext.Viewport', {
  13.                 layout:'border',
  14.                 items: [{
  15.                     id:'btns',
  16.                     region:'west',
  17.                     baseCls:'x-plain',
  18.                     split:true,
  19.                     width:150,
  20.                     minWidth: 100,
  21.                     maxWidth: 250,
  22.                     layout:'fit',
  23.                     margins: '5 0 5 5',
  24.                     items: {
  25.                         baseCls: 'x-plain',
  26.                         html: '<p style="padding:10px;color:#556677;font-size:11px;">点击右边的按钮查看效果</p>'
  27.                     }
  28.                }, {
  29.                     region:'center',
  30.                     margins: '5 5 5 0',
  31.                     layout: 'anchor',
  32.                     items:[{
  33.                         anchor: '100%',
  34.                         baseCls:'x-plain',
  35.                         layout: {
  36.                             type:'hbox',
  37.                             padding: 10
  38.                         },
  39.                         defaults:{
  40.                             margins:'0 5 0 0',
  41.                             pressed: false,
  42.                             toggleGroup:'btns',
  43.                             allowDepress: false
  44.                         },
  45.                         items: [{
  46.                             xtype:'button',
  47.                             
  48.                             text: 'Spaced / Align: left',
  49.                             handler: function(){
  50.                                 replace({
  51.                                     layout: {
  52.                                         type:'vbox',
  53.                                         padding:'5',
  54.                                         align:'left'
  55.                                     },
  56.                                     defaults:{margins:'0 0 5 0'},
  57.                                     items:[{
  58.                                         xtype:'button',
  59.                                         text: 'Button 1'
  60.                                     },{
  61.                                         xtype:'tbspacer',
  62.                                         flex:1
  63.                                     },{
  64.                                         xtype:'button',
  65.                                         text: 'Button 2'
  66.                                     },{
  67.                                         xtype:'button',
  68.                                         text: 'Button 3'
  69.                                     },{
  70.                                         xtype:'button',
  71.                                         text: 'Button 4',
  72.                                         margins:'0'
  73.                                     }]
  74.                                 }, 'spaced');
  75.                             }
  76.                         },{
  77.                             xtype:'button',
  78.                             text: 'Multi-Spaced / Align: left',
  79.                             handler: function(){
  80.                                 replace({
  81.                                     layout: {
  82.                                         type:'vbox',
  83.                                         padding:'5',
  84.                                         align:'left'
  85.                                     },
  86.                                     defaults:{margins:'0 0 5 0'},
  87.                                     items:[{
  88.                                         xtype:'button',
  89.                                         text: 'Button 1'
  90.                                     },{
  91.                                         xtype:'tbspacer',
  92.                                         flex:1
  93.                                     },{
  94.                                         xtype:'button',
  95.                                         text: 'Button 2'
  96.                                     },{
  97.                                         xtype:'tbspacer',
  98.                                         flex:1
  99.                                     },{
  100.                                         xtype:'button',
  101.                                         text: 'Button 3'
  102.                                     },{
  103.                                         xtype:'tbspacer',
  104.                                         flex:1
  105.                                     },{
  106.                                         xtype:'button',
  107.                                         text: 'Button 4',
  108.                                         margins:'0'
  109.                                     }]
  110.                                 }, 'multi spaced - align left');
  111.                             }
  112.                         },{
  113.                             xtype:'button',
  114.                             text: 'Align: left',
  115.                             handler: function(){
  116.                                 replace({
  117.                                     layout: {
  118.                                         type:'vbox',
  119.                                         padding:'5',
  120.                                         align:'left'
  121.                                     },
  122.                                     defaults:{margins:'0 0 5 0'},
  123.                                     items:[{
  124.                                         xtype:'button',
  125.                                         text: 'Button 1'
  126.                                     },{
  127.                                         xtype:'button',
  128.                                         text: 'Button 2'
  129.                                     },{
  130.                                         xtype:'button',
  131.                                         text: 'Button 3'
  132.                                     },{
  133.                                         xtype:'button',
  134.                                         text: 'Button 4'
  135.                                     }]
  136.                                 }, 'align left');
  137.                             }
  138.                         },{
  139.                             xtype:'button',
  140.                             text: 'Align: center',
  141.                             handler: function(){
  142.                                 replace({
  143.                                     layout: {
  144.                                         type:'vbox',
  145.                                         padding:'5',
  146.                                         align:'center'
  147.                                     },
  148.                                     defaults:{margins:'0 0 5 0'},
  149.                                     items:[{
  150.                                         xtype:'button',
  151.                                         text: 'Button 1'
  152.                                     },{
  153.                                         xtype:'button',
  154.                                         text: 'Button 2'
  155.                                     },{
  156.                                         xtype:'button',
  157.                                         text: 'Button 3'
  158.                                     },{
  159.                                         xtype:'button',
  160.                                         text: 'Button 4'
  161.                                     }]
  162.                                 }, 'align center');
  163.                             }
  164.                         },{
  165.                             xtype:'button',
  166.                             text: 'Align: stretch',
  167.                             handler: function(){
  168.                                 replace({
  169.                                     layout: {
  170.                                         type:'vbox',
  171.                                         padding:'5',
  172.                                         align:'stretch'
  173.                                     },
  174.                                     defaults:{margins:'0 0 5 0'},
  175.                                     items:[{
  176.                                         xtype:'button',
  177.                                         text: 'Button 1'
  178.                                     },{
  179.                                         xtype:'button',
  180.                                         text: 'Button 2'
  181.                                     },{
  182.                                         xtype:'button',
  183.                                         text: 'Button 3'
  184.                                     },{
  185.                                         xtype:'button',
  186.                                         text: 'Button 4'
  187.                                     }]
  188.                                 }, 'align stretch');
  189.                             }
  190.                         },{
  191.                             xtype:'button',
  192.                             text: 'Align: stretchmax',
  193.                             handler: function(){
  194.                                 replace({
  195.                                     layout: {
  196.                                         type:'vbox',
  197.                                         padding:'5',
  198.                                         align:'stretchmax'
  199.                                     },
  200.                                     defaults:{margins:'0 0 5 0'},
  201.                                     items:[{
  202.                                         xtype:'button',
  203.                                         text: 'Jamie'
  204.                                     },{
  205.                                         xtype:'button',
  206.                                         text: 'Aaron'
  207.                                     },{
  208.                                         xtype:'button',
  209.                                         text: 'Tommy'
  210.                                     },{
  211.                                         xtype:'button',
  212.                                         text: 'Ed '
  213.                                     }]
  214.                                 }, 'align stretchmax');
  215.                             }
  216.                         }]
  217.                     },{
  218.                         anchor: '100%',
  219.                         baseCls:'x-plain',
  220.                         layout: {
  221.                             type:'hbox',
  222.                             padding: '0 10 10'
  223.                         },
  224.                         defaults:{
  225.                             margins:'0 5 0 0',
  226.                             pressed: false,
  227.                             toggleGroup:'btns',
  228.                             allowDepress: false
  229.                         },
  230.                         items: [{
  231.                             xtype:'button',
  232.                             text: 'Flex: Even / Align: center',
  233.                             handler: function(){
  234.                                 replace({
  235.                                     layout: {
  236.                                         type:'vbox',
  237.                                         padding:'5',
  238.                                         align:'center'
  239.                                     },
  240.                                     defaults:{margins:'0 0 5 0'},
  241.                                     items:[{
  242.                                         xtype:'button',
  243.                                         text: 'Button 1',
  244.                                         flex:1
  245.                                     },{
  246.                                         xtype:'button',
  247.                                         text: 'Button 2',
  248.                                         flex:1
  249.                                     },{
  250.                                         xtype:'button',
  251.                                         text: 'Button 3',
  252.                                         flex:1
  253.                                     },{
  254.                                         xtype:'button',
  255.                                         text: 'Button 4',
  256.                                         flex:1,
  257.                                         margins:'0'
  258.                                     }]
  259.                                 }, 'align flex even');
  260.                             }
  261.                         },{
  262.                             xtype:'button',
  263.                             text: 'Flex: Ratio / Align: center',
  264.                             handler: function(){
  265.                                 replace({
  266.                                     layout: {
  267.                                         type:'vbox',
  268.                                         padding:'5',
  269.                                         align:'center'
  270.                                     },
  271.                                     defaults:{margins:'0 0 5 0'},
  272.                                     items:[{
  273.                                         xtype:'button',
  274.                                         text: 'Button 1',
  275.                                         flex:1
  276.                                     },{
  277.                                         xtype:'button',
  278.                                         text: 'Button 2',
  279.                                         flex:1
  280.                                     },{
  281.                                         xtype:'button',
  282.                                         text: 'Button 3',
  283.                                         flex:1
  284.                                     },{
  285.                                         xtype:'button',
  286.                                         text: 'Button 4',
  287.                                         flex:3,
  288.                                         margins:'0'
  289.                                     }]
  290.                                 }, 'align flex ratio');
  291.                             }
  292.                         },{
  293.                             xtype:'button',
  294.                             text: 'Flex + Stretch',
  295.                             handler: function(){
  296.                                 replace({
  297.                                     layout: {
  298.                                         type:'vbox',
  299.                                         padding:'5',
  300.                                         align:'stretch'
  301.                                     },
  302.                                     defaults:{margins:'0 0 5 0'},
  303.                                     items:[{
  304.                                         xtype:'button',
  305.                                         text: 'Button 1',
  306.                                         flex:1
  307.                                     },{
  308.                                         xtype:'button',
  309.                                         text: 'Button 2',
  310.                                         flex:1
  311.                                     },{
  312.                                         xtype:'button',
  313.                                         text: 'Button 3',
  314.                                         flex:1
  315.                                     },{
  316.                                         xtype:'button',
  317.                                         text: 'Button 4',
  318.                                         flex:3,
  319.                                         margins:'0'
  320.                                     }]
  321.                                 }, 'align flex + stretch');
  322.                             }
  323.                         },{
  324.                             xtype:'button',
  325.                             text: 'Pack: start / Align: center',
  326.                             handler: function(){
  327.                                 replace({
  328.                                     layout: {
  329.                                         type:'vbox',
  330.                                         padding:'5',
  331.                                         pack:'start',
  332.                                         align:'center'
  333.                                     },
  334.                                     defaults:{margins:'0 0 5 0'},
  335.                                     items:[{
  336.                                         xtype:'button',
  337.                                         text: 'Button 1'
  338.                                     },{
  339.                                         xtype:'button',
  340.                                         text: 'Button 2'
  341.                                     },{
  342.                                         xtype:'button',
  343.                                         text: 'Button 3'
  344.                                     },{
  345.                                         xtype:'button',
  346.                                         text: 'Button 4'
  347.                                     }]
  348.                                 }, 'align pack start + align center');
  349.                             }
  350.                         },{
  351.                             xtype:'button',
  352.                             text: 'Pack: center / Align: center',
  353.                             handler: function(){
  354.                                 replace({
  355.                                     layout: {
  356.                                         type:'vbox',
  357.                                         padding:'5',
  358.                                         pack:'center',
  359.                                         align:'center'
  360.                                     },
  361.                                     defaults:{margins:'0 0 5 0'},
  362.                                     items:[{
  363.                                         xtype:'button',
  364.                                         text: 'Button 1'
  365.                                     },{
  366.                                         xtype:'button',
  367.                                         text: 'Button 2'
  368.                                     },{
  369.                                         xtype:'button',
  370.                                         text: 'Button 3'
  371.                                     },{
  372.                                         xtype:'button',
  373.                                         text: 'Button 4',
  374.                                         margins:'0'
  375.                                     }]
  376.                                 }, 'align pack center + align center');
  377.                             }
  378.                         },{
  379.                             xtype:'button',
  380.                             text: 'Pack: end / Align: center',
  381.                             handler: function(){
  382.                                 replace({
  383.                                     layout: {
  384.                                         type:'vbox',
  385.                                         padding:'5',
  386.                                         pack:'end',
  387.                                         align:'center'
  388.                                     },
  389.                                     defaults:{margins:'0 0 5 0'},
  390.                                     items:[{
  391.                                         xtype:'button',
  392.                                         text: 'Button 1'
  393.                                     },{
  394.                                         xtype:'button',
  395.                                         text: 'Button 2'
  396.                                     },{
  397.                                         xtype:'button',
  398.                                         text: 'Button 3'
  399.                                     },{
  400.                                         xtype:'button',
  401.                                         text: 'Button 4',
  402.                                         margins:'0'
  403.                                     }]
  404.                                 }, 'align pack end + align center');
  405.                             }
  406.                         }]
  407.                     }]
  408.                 }]
  409.             });
  410.         });

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值