要使用VBox布局方式,首先的熟悉下一下几个主要属性:
一、align:字符类型,指示组件在容器内的对齐方式。有如下几种属性。
1、left(默认):排列于容器左侧。
2、center :控件在容器水平居中。
3、stretch:控件横向拉伸至容器大小
4、stretchmax:控件横向拉伸,宽度为最宽控件的宽。
二、flex:数字类型,指示组件在容器中水平呈现方式,通俗的讲,就是指示组件在容器中的相对宽度。
三、pack : 字符类型,指示组件在容器的位置,有如下几种属性。
1、start(默认):组件在容器上边
2、center:组件在容器中间
3、end:组件在容器的下边
HTML代码:
- <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <htmlxmlns="http://www.w3.org/1999/xhtml">
- <head>
- <metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
- <title>VBox---MHZG.NET</title>
- <linkrel="stylesheet"type="text/css"href="../../resources/css/ext-all.css"/>
- <scripttype="text/javascript"src="../../bootstrap.js"></script>
- <scripttype="text/javascript"src="../../locale/ext-lang-zh_CN.js"></script>
- <scripttype="text/javascript"src="vbox.js"></script>
- <styletype="text/css">
- html,body{
- font:normal12pxverdana;
- margin:0;
- padding:0;
- border:0none;
- }
- </style>
- </head>
-
- <body>
- </body>
- </html>
vbox.js:
- Ext.onReady(function(){
- varcurrentName;
- varreplace=function(config,name){
- varbtns=Ext.getCmp('btns');
- if(name&&name!=currentName){
- currentName=name;
- btns.remove(0);
- btns.add(Ext.apply(config));
- }
- };
- varviewport=Ext.create('Ext.Viewport',{
- layout:'border',
-
- items:[{
- id:'btns',
- region:'west',
- baseCls:'x-plain',
- split:true,
- width:150,
- minWidth:100,
- maxWidth:250,
- layout:'fit',
- margins:'5055',
- items:{
- baseCls:'x-plain',
- html:'<pstyle="padding:10px;color:#556677;font-size:11px;">点击右边的按钮查看效果</p>'
- }
- },{
- region:'center',
- margins:'5550',
- layout:'anchor',
- items:[{
- anchor:'100%',
- baseCls:'x-plain',
- layout:{
- type:'hbox',
- padding:10
- },
- defaults:{
- margins:'0500',
- pressed:false,
- toggleGroup:'btns',
- allowDepress:false
- },
- items:[{
- xtype:'button',
- text:'Spaced/Align:left',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- align:'left'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Button1'
- },{
- xtype:'tbspacer',
- flex:1
- },{
- xtype:'button',
- text:'Button2'
- },{
- xtype:'button',
- text:'Button3'
- },{
- xtype:'button',
- text:'Button4',
- margins:'0'
- }]
- },'spaced');
- }
- },{
- xtype:'button',
- text:'Multi-Spaced/Align:left',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- align:'left'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Button1'
- },{
- xtype:'tbspacer',
- flex:1
- },{
- xtype:'button',
- text:'Button2'
- },{
- xtype:'tbspacer',
- flex:1
- },{
- xtype:'button',
- text:'Button3'
- },{
- xtype:'tbspacer',
- flex:1
- },{
- xtype:'button',
- text:'Button4',
- margins:'0'
- }]
- },'multispaced-alignleft');
- }
- },{
- xtype:'button',
- text:'Align:left',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- align:'left'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Button1'
- },{
- xtype:'button',
- text:'Button2'
- },{
- xtype:'button',
- text:'Button3'
- },{
- xtype:'button',
- text:'Button4'
- }]
- },'alignleft');
- }
- },{
- xtype:'button',
- text:'Align:center',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- align:'center'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Button1'
- },{
- xtype:'button',
- text:'Button2'
- },{
- xtype:'button',
- text:'Button3'
- },{
- xtype:'button',
- text:'Button4'
- }]
- },'aligncenter');
- }
- },{
- xtype:'button',
- text:'Align:stretch',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- align:'stretch'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Button1'
- },{
- xtype:'button',
- text:'Button2'
- },{
- xtype:'button',
- text:'Button3'
- },{
- xtype:'button',
- text:'Button4'
- }]
- },'alignstretch');
- }
- },{
- xtype:'button',
- text:'Align:stretchmax',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- align:'stretchmax'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Jamie'
- },{
- xtype:'button',
- text:'Aaron'
- },{
- xtype:'button',
- text:'Tommy'
- },{
- xtype:'button',
- text:'Ed'
- }]
- },'alignstretchmax');
- }
- }]
- },{
- anchor:'100%',
- baseCls:'x-plain',
- layout:{
- type:'hbox',
- padding:'01010'
- },
- defaults:{
- margins:'0500',
- pressed:false,
- toggleGroup:'btns',
- allowDepress:false
- },
- items:[{
- xtype:'button',
- text:'Flex:Even/Align:center',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- align:'center'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Button1',
- flex:1
- },{
- xtype:'button',
- text:'Button2',
- flex:1
- },{
- xtype:'button',
- text:'Button3',
- flex:1
- },{
- xtype:'button',
- text:'Button4',
- flex:1,
- margins:'0'
- }]
- },'alignflexeven');
- }
- },{
- xtype:'button',
- text:'Flex:Ratio/Align:center',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- align:'center'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Button1',
- flex:1
- },{
- xtype:'button',
- text:'Button2',
- flex:1
- },{
- xtype:'button',
- text:'Button3',
- flex:1
- },{
- xtype:'button',
- text:'Button4',
- flex:3,
- margins:'0'
- }]
- },'alignflexratio');
- }
- },{
- xtype:'button',
- text:'Flex+Stretch',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- align:'stretch'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Button1',
- flex:1
- },{
- xtype:'button',
- text:'Button2',
- flex:1
- },{
- xtype:'button',
- text:'Button3',
- flex:1
- },{
- xtype:'button',
- text:'Button4',
- flex:3,
- margins:'0'
- }]
- },'alignflex+stretch');
- }
- },{
- xtype:'button',
- text:'Pack:start/Align:center',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- pack:'start',
- align:'center'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Button1'
- },{
- xtype:'button',
- text:'Button2'
- },{
- xtype:'button',
- text:'Button3'
- },{
- xtype:'button',
- text:'Button4'
- }]
- },'alignpackstart+aligncenter');
- }
- },{
- xtype:'button',
- text:'Pack:center/Align:center',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- pack:'center',
- align:'center'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Button1'
- },{
- xtype:'button',
- text:'Button2'
- },{
- xtype:'button',
- text:'Button3'
- },{
- xtype:'button',
- text:'Button4',
- margins:'0'
- }]
- },'alignpackcenter+aligncenter');
- }
- },{
- xtype:'button',
- text:'Pack:end/Align:center',
- handler:function(){
- replace({
- layout:{
- type:'vbox',
- padding:'5',
- pack:'end',
- align:'center'
- },
- defaults:{margins:'0050'},
- items:[{
- xtype:'button',
- text:'Button1'
- },{
- xtype:'button',
- text:'Button2'
- },{
- xtype:'button',
- text:'Button3'
- },{
- xtype:'button',
- text:'Button4',
- margins:'0'
- }]
- },'alignpackend+aligncenter');
- }
- }]
- }]
- }]
- });
- });
本文介绍了VBox布局方式及其主要属性,包括align、flex和pack,并通过实例展示了不同属性设置的效果。
2628

被折叠的 条评论
为什么被折叠?



