Search code examples
extjssencha-touchsencha-touch-2

Align items vertically in a center - Sencha Panel


I am trying to align mid of the screen of an item simply a label but it is aligning it horizontally not vertically.

var panel = new Ext.Panel({
    layout:{
        type: 'vbox',
        align: 'center'
    },
    items:[
        {
            xtype: 'label',
            html: 'My Label'
        }
    ],
    fullscreen: true,
    flex: 1
});

I have removed flex, and set height as well, but it doesn't work. Please give me some clue?


Solution

  • Try using pack: center in the layout, like this:

    var panel = new Ext.Panel({
        layout: {
            type: 'hbox',
            align: 'center',
            pack: 'center'
        }, 
        items:[
            {
                xtype: 'label',
                html: 'My Label'
            }
        ]
    });