Sencha Touch 之 layout(布局)

本文详细介绍了ExtJS中四种主要布局方式:HBox(水平纵向排列)、VBox(水平横向排列)、Fit(子组件适应父容器全尺寸)及Docking(水平纵向对接),并提供了具体的代码实现示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一:HBox
水平纵向排列

代码:
Ext.application({
    name: 'MyApp',

    launch: function() {
        Ext .create('Ext.Container' ,{
            fullscreen: true,  //全屏
            layout: 'hbox',  //水平纵向布局
            items:[
                  {
                        xtype: 'panel',
                        html: '消息列表' ,
                        flex:1  //宽度所占比例为全屏的1/3
                  },
                  {
                        xtype: 'panel',
                        html: '消息视图' ,
                        flex:3
                  }
            ]
        })
    }  
});
二:VBox
水平横向(垂直)排列

代码:
Ext.application({
    name: 'MyApp',

    launch: function() {
        Ext .create('Ext.Container' ,{
            fullscreen: true,
            layout: 'vbox',
            items:[
                  {
                        xtype: 'panel',
                        html: '消息列表' ,
                        flex:1  //高度所占比为全屏高度的1/3
                  },
                  {
                        xtype: 'panel',
                        html: '消息视图' ,
                        flex:2
                  }
            ]
        })
    }  
});
三:Fit
子组件适应父类容器的全尺寸(全屏)

代码:
Ext.application({
    name: 'MyApp',
    launch: function() {
       var panel = Ext .create('Ext.Panel' ,{
            width:200,
            height:200,
            layout: 'fit',  //充满父类窗口
            items:[
                  {
                        xtype: 'panel',
                        html: 'Also 200px by 200px'
                  }
            ]
        });
      Ext .Viewport.add(panel);
    }  
});
四:Docking(对接)
水平纵向对接

代码:
Ext.application({
    name: 'MyApp',
    launch: function() {
       var panel = Ext .create('Ext.Container' ,{
            fullscreen: true,
            layout: 'hbox',
            items:[
                  {
                        docked: 'top',  //对接位置
                        xtype: 'panel',
                        height: '50',
                        html: 'This is docked to the top'
                  },
                  {
                        xtype: 'panel',
                        html: '消息列表' ,
                        flex:1
                  },
                  {
                        xtype: 'panel',
                        html: '消息视图' ,
                        flex:2
                  }
            ]
        });
    }  
});
水平纵向对接

代码:
Ext.application({
    name: 'MyApp',
    launch: function() {
       var panel = Ext .create('Ext.Container' ,{
            fullscreen: true,
            layout: 'hbox',
            items:[
                  {
                        docked: 'left',  //对接位置
                        xtype: 'panel',
                        height: '50',
                        html: 'This is docked to the top'
                  },
                  {
                        xtype: 'panel',
                        html: '消息列表' ,
                        flex:1
                  },
                  {
                        xtype: 'panel',
                        html: '消息视图' ,
                        flex:2
                  }
            ]
        });
    }  
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值