Sencha Touch快速入门2.0之Box布局

移动开发
Sencha Touch快速入门2.0之Box布局是本文要介绍的内容,Sencha touch里的布局应该理解为:该控件内部子项的排列方式。

Sencha Touch快速入门2.0之Box布局是本文要介绍的内容,上一篇讲到Sencha Touch快速入门2.0之Chorme浏览器调试功能介绍,接着在学习布局的内容。

Sencha Touch里的布局有五种

hbox

vbox

card

fit

auto[默认]

实际上可以分为Box布局和Fit布局两种。

Sencha touch里的布局应该理解为:该控件内部子项的排列方式。

我们今天先来看看box布局

Box布局

顾名思义,box布局就是一个个的box组成的。

hbox: 水平排列、垂直居中、靠左置顶

vbox: 竖直堆叠、水平居中、靠上置顶

hbox:

  1. hbox   
  2. Ext.setup({      
  3.   tabletStartupScreen: 'tablet_startup.png',      
  4.   phoneStartupScreen: 'phone_startup.png',      
  5.   icon: 'icon.png',      
  6.   glossOnIcon: false,      
  7.   onReady : function() {          
  8.     var pnl = new Ext.Panel({              
  9.     fullscreen: true,              
  10.     layout: 'hbox',              
  11.   items:[                  
  12.      {xtype:'button',text:'按钮1'},                  
  13.      {xtype:'button',text:'按钮2'},                  
  14.      {xtype:'button',text:'按钮3'}             
  15.      ]         
  16.    });      
  17. }});  
  18.    
  19. vbox: 

Sencha Touch快速入门2.0之Box布局

将以上的hbox改为vbox

Sencha Touch快速入门2.0之Box布局

但是,只是知道这些,还不足以玩转box布局,下面让我们看看其他常见的box布局实例。

vbox变型:

  1. vbox变型   
  2. Ext.setup({      
  3. tabletStartupScreen: 'tablet_startup.png',      
  4. phoneStartupScreen: 'phone_startup.png',      
  5. icon: 'icon.png',      
  6. glossOnIcon: false,      
  7. onReady : function() {          
  8. var pnl = new Ext.Panel({              
  9. fullscreen: true,              
  10. layout: 'vbox',              
  11. defaults: {                  
  12. flex: 1              
  13. },              
  14.   items:[                  
  15.   {xtype:'button',text:'按钮1'},                  
  16.   {xtype:'button',text:'按钮2'},                  
  17.   {xtype:'button',text:'按钮3'}             
  18.   ]          
  19.  });      
  20. }}); 

Sencha Touch快速入门2.0之Box布局

关于这里的flex,sencha Touch使用了css3中的弹性和模型,所以大家如果有兴趣可以看看 扩展阅读:css3中的弹性盒模型

vbox变型2:

在上面代码的defaults中加入width : '100%',得到下图

Sencha Touch快速入门2.0之Box布局

了解以上内容之后,我们来想想经典的九宫格布局如何实现吧!

相必大家也已经心中有数了。

经典的九宫格布局:

九宫格

  1. Ext.setup({      
  2. tabletStartupScreen: 'tablet_startup.png',    p  
  3. honeStartupScreen: 'phone_startup.png',      
  4. icon: 'icon.png',      
  5. glossOnIcon: false,      
  6. onReady : function() {          
  7. var pnl = new Ext.Panel({              
  8. fullscreen: true,             
  9.  layout: 'vbox',              
  10.  defaults: {                  
  11.  flex: 1,                  
  12.  width: '100%',                  
  13.  defaults: {                      
  14.  flex: 1,                     
  15.   height: '100%'    
  16.   }                  
  17.  },              
  18.  items:[{                 
  19.        xtype: 'panel',    
  20.        layout: 'hbox',    
  21.  items:[                      
  22.     {xtype:'button',text:'按钮1'},    
  23.     {xtype:'button',text:'按钮2'},   
  24.     {xtype:'button',text:'按钮3'}     
  25.   ]              
  26.  },{                 
  27.  xtype: 'panel',       
  28.  layout: 'hbox',     
  29. items:[                      
  30.    {xtype:'button',text:'按钮4'},    
  31.    {xtype:'button',text:'按钮5'},  
  32.    {xtype:'button',text:'按钮6'}]    
  33.  },{                  
  34.  xtype: 'panel',  
  35.  layout: 'hbox',   
  36.  items:[    
  37.  {xtype:'button',text:'按钮7'},    
  38.  {xtype:'button',text:'按钮8'},   
  39.  {xtype:'button',text:'按钮9'}   
  40. ]             
  41. }]          
  42. });     
  43. }}); 

Sencha Touch快速入门2.0之Box布局

嫌紧挨着不舒服?别急,我们还有些属性没用上!你没有猜错那就是-----margin、padding!你知道怎么做的!

松散九宫格:

松散九宫格

  1. Ext.setup({     
  2.   tabletStartupScreen: 'tablet_startup.png',      
  3.   phoneStartupScreen: 'phone_startup.png',      
  4.   icon: 'icon.png',      
  5.   glossOnIcon: false,      
  6.   onReady : function() {          
  7.     var pnl = new Ext.Panel({     
  8.     fullscreen: true,    
  9.     layout: 'vbox',   
  10.     defaults: {     
  11.   flex: 1,      
  12.   width: '100%',    
  13.    padding: 10,   
  14.    defaults: {    
  15.     flex: 1,     
  16.     height: '100%',   
  17.     margin: 10                  
  18.   }                  
  19. },              
  20.  items:[{         
  21.           xtype: 'panel',   
  22.           layout: 'hbox',   
  23.  items:[           
  24.             {xtype:'button',text:'按钮1'},   
  25.             {xtype:'button',text:'按钮2'},   
  26.             {xtype:'button',text:'按钮3'}          
  27.       ]            
  28.    },{                 
  29.     xtype: 'panel',   
  30.     layout: 'hbox',    
  31.     items:[            
  32.               {xtype:'button',text:'按钮4'},    
  33.               {xtype:'button',text:'按钮5'},      
  34.               {xtype:'button',text:'按钮6'}       
  35.           ]             
  36.     },{                  
  37.      xtype: 'panel',                  
  38.      layout: 'hbox',       
  39.   items:[                      
  40.      {xtype:'button',text:'按钮7'},     
  41.      {xtype:'button',text:'按钮8'},      
  42.      {xtype:'button',text:'按钮9'}     
  43.    ]              
  44.  }]          
  45. });      
  46. }}); 

Sencha Touch快速入门2.0之Box布局

OK,到这里,你已经可以对box已经可以运用自如了,下一篇,我们将接着讲解sencha touch里的另一种布局“Fit”布局

小结:Sencha Touch快速入门2.0之Box布局的内容介绍完了,希望通过本文的学习能对你有所帮助!

责任编辑:zhaolei 来源: 博客园
相关推荐

2011-09-02 15:58:38

Sencha Touc布局

2011-09-02 15:18:49

Sencha Touc

2011-09-02 16:08:09

Sencha ToucAPI文档

2011-09-02 15:28:10

Sencha Touc浏览器

2011-10-26 10:12:53

Sencha Touc布局

2012-01-10 13:21:33

Sencha Touc使用data包

2011-10-26 10:43:19

Sencha Touc

2011-09-30 14:15:10

Sencha ToucSencha Touc

2011-10-26 10:21:40

Sencha Touc组件

2011-09-02 15:12:29

PhoneGapSencha Touc

2011-10-26 10:32:05

Sencha Touc数据视图

2011-10-18 09:49:40

新特征Sencha Touc

2011-07-25 15:55:21

Sencha ToucHtml 5

2011-07-26 09:41:50

Sencha Touc特性HTML 5

2010-11-22 10:31:17

Sencha touc

2011-11-16 13:14:02

Sencha TouciOS本地应用

2011-07-26 09:46:53

Sencha Touc

2011-07-25 16:21:22

Sencha touc

2011-09-05 10:20:21

Sencha ToucAPP

2011-11-28 13:42:55

Sencha Touc组件选择器
点赞
收藏

51CTO技术栈公众号