`
dowhathowtodo
  • 浏览: 778744 次
文章分类
社区版块
存档分类
最新评论

ExtJS4学习笔记(五)---VBox的使用

 
阅读更多

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

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

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

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

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

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

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

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

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

2、center:组件在容器中间

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

HTML代码:

  1. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <htmlxmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
  5. <title>VBox---MHZG.NET</title>
  6. <linkrel="stylesheet"type="text/css"href="../../resources/css/ext-all.css"/>
  7. <scripttype="text/javascript"src="../../bootstrap.js"></script>
  8. <scripttype="text/javascript"src="../../locale/ext-lang-zh_CN.js"></script>
  9. <scripttype="text/javascript"src="vbox.js"></script>
  10. <styletype="text/css">
  11. html,body{
  12. font:normal12pxverdana;
  13. margin:0;
  14. padding:0;
  15. border:0none;
  16. }
  17. </style>
  18. </head>

  19. <body>
  20. </body>
  21. </html>

vbox.js:

  1. Ext.onReady(function(){
  2. varcurrentName;
  3. varreplace=function(config,name){
  4. varbtns=Ext.getCmp('btns');
  5. if(name&&name!=currentName){
  6. currentName=name;
  7. btns.remove(0);
  8. btns.add(Ext.apply(config));
  9. }
  10. };
  11. varviewport=Ext.create('Ext.Viewport',{
  12. layout:'border',

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics