EXTJS 中 anchor 的用法

anchor布局将使组件固定于父容器的某一个位置,使用anchor布局的子组件尺寸相对于容器的尺寸,即父容器容器的大小发生变化时,使用anchor布局的组件会根据规定的规则重新渲染位置和大小。

AnchorLayout布局没有任何的直接配置选项(继承的除外),然而在使用AnchorLayout布局时,其子组件都有一个anchor属性,用来配置此子组件在父容器中所处的位置。

anchor属性为一组字符串,可以使用百分比或者是-数字来表示。配置字符串使用空格隔开,例如

anchor:'75% 25%',表示宽度为父容器的75%,高度为父容器的25%

anchor:'-300 -200',表示组件相对于父容器右边距为300,相对于父容器的底部位200

anchor:'-250 20%',混合模式,表示组件党对于如容器右边为250,高度为父容器的20%

示例代码:

  1. Ext.application(  
  2.         {  
  3.             name:'layout_anchor',  
  4.             launch:function(){  
  5.                 Ext.create(  
  6.                     'Ext.panel.Panel',  
  7.                     {  
  8.                         width:500,  
  9.                         height:300,  
  10.                         title:'anchor布局',  
  11.                         layout:'anchor',  
  12.                         x:60,  
  13.                         y:80,  
  14.                         renderTo:Ext.getBody(),  
  15.                         items:[  
  16.                                {  
  17.                                    xtype:'panel',  
  18.                                    title:'第一个',  
  19.                                    //表示宽度为父容器的75%,高度为父容器的20%  
  20.                                    anchor:'75% 20%'  
  21.                                },{  
  22.                                    xtype:'panel',  
  23.                                    title:'第二个',  
  24.                                    //表示相对于父容器右边距为130,相对于父容器下边距为120  
  25.                                    anchor:'-130 -120'  
  26.                                }  
  27.                         ]  
  28.                     }  
  29.                 )  
  30.             }  
  31.         }  



  1. {  
  2.                    columnWidth:0.33,  
  3.                      layout:'form',  
  4.                          items:[{  
  5.                   id:'missiontype',  
  6.                   name:"mission.missiontype",  
  7.                   xtype:'combo',  
  8.                   fieldLabel:'任务类型',  
  9.                   editable:false,  
  10.                   store : gdlxStore,  
  11.                   displayField:'gdlx',  
  12.                    mode:'local',  
  13.                   anchor:'100%',  
  14.                   listeners:{  
  15.                         'select':function(combo, record,index){  
  16.                         dmlxCom.clearValue();   
  17.                         if(this.getValue())  
  18.                           dmlxStore.load({params:{missionType:this.getValue()}});  
  19.                           //gdlxStore.reload();  
  20.                                 }  
  21.                                     }  
  22.          }]  
  23.          }  



 ext中许多组件都有anchor这个属性,他一般与布局column一起使用,以文本组件为例:columnWidth的值乘以anchor的值,即为本组件所占的长度。

另外注意:anchor不可与设置长度的属性width同时出现,否则,width属性无效

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值