设为首页 收藏本站
查看: 1172|回复: 0

[经验分享] Extjs Vbox布局方式,以及align种类,flex,pack属性含义简介

[复制链接]

尚未签到

发表于 2015-4-17 07:53:24 | 显示全部楼层 |阅读模式
  
  VBox布局方式,熟悉下一下几个主要属性:
一、align:字符类型,指示组件在容器内的对齐方式。这个是基于容器的左上角来排列的。pack不同,pack是根据容器的最上边来显示的。
       1、left(默认):排列于容器左侧。  
       2、center :控件在容器水平居中。   
       3、stretch:控件横向拉伸至容器大小 。
       4、stretchmax:控件横向拉伸,宽度为最宽控件的宽。
  二、flex:数字类型,指示组件在容器中的呈现方式,就是指示组件在容器中的相对宽度或高度。
       如果容器本身排列方式是水平的,那么组件会根据容器的宽度进行显示,单个组件,指定了flex属性值,不论是哪个数值都会充满容器宽度,如果有n个组件,那么就按照每个组件的宽度:
       d(i)=w(container)/sum(flex1-n) * flex, 即按照比例来显示宽度。竖直方向也类似。
       读者们可以自行修改以下代码尝试下,若是本人理解有误,请帮忙指证下,谢谢。
  三、pack : 字符类型,指示组件在容器的位置。pack是上边,中边,下边,跟excel表格里的文字对齐方式类似。
      1、start(默认):组件在容器上边   
      2、center:组件在容器中间     
      3、end:组件在容器的下边
  一行行写代码不容易,把代码贴出来,各位博友方便粘过去浏览器玩玩。
  html代码(要引入Extjs的js文件):


DSC0000.gif DSC0001.gif


1
2
3
4     
5     Test Extjs Vbox
6     
7     
8     
9
10
11
12
13
testVbox.html  Extjs代码,通过看图片就能很清晰了,其中flex数字,





  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             {
16                 id : 'btns',
17                 region : 'west',
18                 baseCls : 'x-plain',
19                 split : true,
20                 width : 150,
21                 minWidth : 100,
22                 maxWidth : 250,
23                 layout : 'fit',
24                 margins : '5 0 5 5',
25                 items : {
26                     baseCls : 'x-plain',
27                     html : '点击右边的按钮查看效果'
28                 }
29             },
30             {
31                 region : 'center',
32                 margins : '5 5 5 0',
33                 layout : 'anchor',
34                 items : [
35                     {
36                         anchor : '100%',
37                         baseCls : 'x-plain',
38                         layout : {
39                             type : 'hbox',
40                             padding : 10
41                         },
42                         defaults : {
43                             margins : '0 5 0 0',
44                             prssed : false,
45                             toogleGroup : 'btns',
46                             allowDepress : false
47                         },
48                         items : [
49                             {
50                                 xtype : 'button',
51                                 text : 'Spaced / Align: left',
52                                 handler : function() {
53                                     replace({
54                                         layout : {
55                                             type : 'vbox',
56                                             padding : '5',
57                                             align : 'left'
58                                         },
59                                         defaults : {
60                                             margins : '0 0 5 0'
61                                         },
62                                         items : [
63                                             {
64                                                 xtype : 'button',
65                                                 text : 'Button 1'
66                                             },
67                                             {
68                                                 xtype : 'tbspacer',
69                                                 flex : 1
70                                             },
71                                             {
72                                                 xtype : 'button',
73                                                 text : 'Button 2'
74                                             },
75                                             {
76                                                 xtype : 'button',
77                                                 text : 'Button 3'
78                                             },
79                                             {
80                                                 xtype : 'button',
81                                                 text : 'Button 4',
82                                                 margins : '0'
83                                             }
84                                         ]
85                                     }, 'spaced');
86                                 }
87                             },
88                             {
89                                 xtype : 'button',
90                                 text : 'Multi-Spaced / Align : left',
91                                 handler : function() {
92                                     replace(
93                                         {
94                                             layout : {
95                                             type : 'vbox',
96                                             padding : '5',
97                                             align : 'left'
98                                         },
99                                         defaults : {
100                                             margins : '0 0 5 0'
101                                         },
102                                         items : [
103                                             {
104                                                 xtype : 'button',
105                                                 text : 'Button 1'
106                                             },
107                                             {
108                                                 xtype : 'tbspacer',
109                                                 flex : 1
110                                             },
111                                             {
112                                                 xtype : 'button',
113                                                 text : 'Button 2'
114                                             },
115                                             {
116                                                 xtype : 'button',
117                                                 text : 'Button 3'
118                                             },
119                                             {
120                                                 xtype : 'button',
121                                                 text : 'Button 4',
122                                                 margins : '0'
123                                             }
124                                         ]
125                                         }, 'Multi spaced - align left');
126                                 }
127                             },
128                             {
129                                 xtype : 'button',
130                                 text : 'Align : left',
131                                 handler : function() {
132                                     replace(
133                                         {
134                                             layout : {
135                                             type : 'vbox',
136                                             padding : '5',
137                                             align : 'left'
138                                         },
139                                         defaults : {
140                                             margins : '0 0 5 0'
141                                         },
142                                         items : [
143                                             {
144                                                 xtype : 'button',
145                                                 text : 'Button 1'
146                                             },
147                                             {
148                                                 xtype : 'button',
149                                                 text : 'Button 2'
150                                             },
151                                             {
152                                                 xtype : 'button',
153                                                 text : 'Button 3'
154                                             },
155                                             {
156                                                 xtype : 'button',
157                                                 text : 'Button 4',
158                                             }
159                                         ]
160                                         }, 'align left');
161                                 }
162                             },
163                             {
164                                 xtype : 'button',
165                                 text : 'Align : Center',
166                                 handler : function() {
167                                     replace(
168                                         {
169                                             layout : {
170                                             type : 'vbox',
171                                             padding : '5',
172                                             align : 'center'
173                                         },
174                                         defaults : {
175                                             margins : '0 0 5 0'
176                                         },
177                                         items : [
178                                             {
179                                                 xtype : 'button',
180                                                 text : 'Button 1'
181                                             },
182                                             {
183                                                 xtype : 'button',
184                                                 text : 'Button 2'
185                                             },
186                                             {
187                                                 xtype : 'button',
188                                                 text : 'Button 3'
189                                             },
190                                             {
191                                                 xtype : 'button',
192                                                 text : 'Button 4'
193                                             }
194                                         ]
195                                         }, 'align center');
196                                 }
197                             },
198                             {
199                                 xtype : 'button',
200                                 text : 'Align : Stretch',
201                                 handler : function() {
202                                     replace(
203                                         {
204                                             layout : {
205                                             type : 'vbox',
206                                             padding : '5',
207                                             align : 'stretch'
208                                         },
209                                         defaults : {
210                                             margins : '0 0 5 0'
211                                         },
212                                         items : [
213                                             {
214                                                 xtype : 'button',
215                                                 text : 'Button 1'
216                                             },
217                                             {
218                                                 xtype : 'button',
219                                                 text : 'Button 2'
220                                             },
221                                             {
222                                                 xtype : 'button',
223                                                 text : 'Button 3'
224                                             },
225                                             {
226                                                 xtype : 'button',
227                                                 text : 'Button 4'
228                                             }
229                                         ]
230                                         }, 'align stretch');
231                                 }
232                             },
233                             {
234                                 xtype : 'button',
235                                 text : 'Align : Stretchmax',
236                                 handler : function() {
237                                     replace(
238                                         {
239                                             layout : {
240                                             type : 'vbox',
241                                             padding : '5',
242                                             align : 'stretchmax'
243                                         },
244                                         defaults : {
245                                             margins : '0 0 5 0'
246                                         },
247                                         items : [
248                                             {
249                                                 xtype : 'button',
250                                                 text : 'Jamie1'
251                                             },
252                                             {
253                                                 xtype : 'button',
254                                                 text : 'Aaron2'
255                                             },
256                                             {
257                                                 xtype : 'button',
258                                                 text : 'Tommy3'
259                                             },
260                                             {
261                                                 xtype : 'button',
262                                                 text : 'Ed4'
263                                             }
264                                         ]
265                                         }, 'align stretchmax');
266                                 }
267                             }
268                         ]
269                     },
270                     {
271                         anchor : '100%',
272                         baseCls : 'x-plain',
273                         layout : {
274                             type : 'hbox',
275                             padding : '0 10 10'
276                         },
277                         defaults : {
278                             margins : '0 5 0 0',
279                             pressed : false,
280                             toggleGroup : 'btns',
281                             allowDepress : false
282                         },
283                         items : [
284                             {
285                                 xtype : 'button',
286                                 text : 'Flex : Even / Align : center',
287                                 handler : function() {
288                                     replace(
289                                         {
290                                             layout : {
291                                             type : 'vbox',
292                                             padding : '5',
293                                             align : 'center'
294                                         },
295                                         defaults : {
296                                             margins : '0 0 5 0'
297                                         },
298                                         items : [
299                                             {
300                                                 xtype : 'button',
301                                                 text : 'Button 1'
302                                             },
303                                             {
304                                                 xtype : 'button',
305                                                 text : 'Button 2'
306                                             },
307                                             {
308                                                 xtype : 'button',
309                                                 text : 'Button 3'
310                                             },
311                                             {
312                                                 xtype : 'button',
313                                                 text : 'Button 4',
314                                                 margins : 0
315                                             }
316                                         ]
317                                         }, 'align flex even');
318                                 }
319                             },
320                             {
321                                 xtype : 'button',
322                                 text : 'Flex : Ratio / Align : center',
323                                 handler : function() {
324                                     replace(
325                                         {
326                                             layout : {
327                                             type : 'vbox',
328                                             padding : '5',
329                                             align : 'center'
330                                         },
331                                         defaults : {
332                                             margins : '0 0 5 0'
333                                         },
334                                         items : [
335                                             {
336                                                 xtype : 'button',
337                                                 text : 'Button 1',
338                                                 flex : 1
339                                             },
340                                             {
341                                                 xtype : 'button',
342                                                 text : 'Button 2',
343                                                 flex : 1
344                                             },
345                                             {
346                                                 xtype : 'button',
347                                                 text : 'Button 3',
348                                                 flex : 1
349                                             },
350                                             {
351                                                 xtype : 'button',
352                                                 text : 'Button 4',
353                                                 margins : 0,
354                                                 flex : 3
355                                             }
356                                         ]
357                                         }, 'align flex=3 ratio');
358                                 }
359                             },
360                             {
361                                 xtype : 'button',
362                                 text : 'Flex + Ratio flex=1,last=3',
363                                 handler : function() {
364                                     replace(
365                                         {
366                                             layout : {
367                                             type : 'vbox',
368                                             padding : '5',
369                                             align : 'stretch'
370                                         },
371                                         defaults : {
372                                             margins : '0 0 5 0'
373                                         },
374                                         items : [
375                                             {
376                                                 xtype : 'button',
377                                                 text : 'Button 1',
378                                                 flex : 1
379                                             },
380                                             {
381                                                 xtype : 'button',
382                                                 text : 'Button 2',
383                                                 flex : 1
384                                             },
385                                             {
386                                                 xtype : 'button',
387                                                 text : 'Button 3',
388                                                 flex : 1
389                                             },
390                                             {
391                                                 xtype : 'button',
392                                                 text : 'Button 4',
393                                                 margins : 0,
394                                                 flex : 3
395                                             }
396                                         ]
397                                         }, 'align flex + stretch');
398                                 }
399                             },
400                             {
401                                 xtype : 'button',
402                                 text : 'Paack : start / Align : center',
403                                 handler : function() {
404                                     replace(
405                                         {
406                                             layout : {
407                                             type : 'vbox',
408                                             padding : '5',
409                                             pack : 'start',
410                                             align : 'center'
411                                         },
412                                         defaults : {
413                                             margins : '0 0 5 0'
414                                         },
415                                         items : [
416                                             {
417                                                 xtype : 'button',
418                                                 text : 'Button 1'
419                                             },
420                                             {
421                                                 xtype : 'button',
422                                                 text : 'Button 2'
423                                             },
424                                             {
425                                                 xtype : 'button',
426                                                 text : 'Button 3'
427                                             },
428                                             {
429                                                 xtype : 'button',
430                                                 text : 'Button 4',
431                                                 margins : 0
432                                             }
433                                         ]
434                                         }, 'align pack start + center');
435                                 }
436                             },
437                             {
438                                 xtype : 'button',
439                                 text : 'Pack : center / Align : center',
440                                 handler : function() {
441                                     replace(
442                                         {
443                                             layout : {
444                                             type : 'vbox',
445                                             padding : '5',
446                                             pack : 'center',
447                                             align : 'center'
448                                         },
449                                         defaults : {
450                                             margins : '0 0 5 0'
451                                         },
452                                         items : [
453                                             {
454                                                 xtype : 'button',
455                                                 text : 'Button 1'
456                                             },
457                                             {
458                                                 xtype : 'button',
459                                                 text : 'Button 2'
460                                             },
461                                             {
462                                                 xtype : 'button',
463                                                 text : 'Button 3'
464                                             },
465                                             {
466                                                 xtype : 'button',
467                                                 text : 'Button 4',
468                                                 margins : 0
469                                             }
470                                         ]
471                                         }, 'align pack center + center');
472                                 }
473                             },
474                             {
475                                 xtype : 'button',
476                                 text : 'Paack : end / Align : center',
477                                 handler : function() {
478                                     replace(
479                                         {
480                                             layout : {
481                                             type : 'vbox',
482                                             padding : '5',
483                                             pack : 'end',
484                                             align : 'center'
485                                         },
486                                         defaults : {
487                                             margins : '0 0 5 0'
488                                         },
489                                         items : [
490                                             {
491                                                 xtype : 'button',
492                                                 text : 'Button 1'
493                                             },
494                                             {
495                                                 xtype : 'button',
496                                                 text : 'Button 2'
497                                             },
498                                             {
499                                                 xtype : 'button',
500                                                 text : 'Button 3'
501                                             },
502                                             {
503                                                 xtype : 'button',
504                                                 text : 'Button 4',
505                                                 margins : 0
506                                             }
507                                         ]
508                                         }, 'align pack end + center');
509                                 }
510                             }
511                         ]
512                     }
513                 ]
514             }
515         ]
516     });
517 });
Extjs_vbox.js  效果图片:
   DSC0002.jpg
   DSC0003.jpg
   DSC0004.jpg
   DSC0005.jpg
   DSC0006.jpg
   DSC0007.jpg
  参考文章:http://wenku.baidu.com/view/914508e94afe04a1b071de0a.html?pn=51

草原战狼淘宝小店:http://xarxf.taobao.com/ 淘宝搜小矮人鞋坊,主营精致美丽时尚女鞋,为您的白雪公主挑一双哦。谢谢各位博友的支持。
  =================================================================================================
  
  ========================    以上分析仅代表个人观点,欢迎指正与交流   ===============
  
  ========================    尊重劳动成果,转载请注明出处,万分感谢   ================
  
  =================================================================================================
  
     DSC0008.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-57867-1-1.html 上篇帖子: 在CentOS6虚拟机上安装VirtualBox增强功能 下篇帖子: 黄聪:从主机访问虚拟机中的网站系列教程(VBox篇)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表