javascript - 如何在中心显示图像 - extjs 4

标签 javascript ajax extjs extjs4

win = Ext.create('widget.window', {
                title: 'View Image',
                closable: true,
                closeAction: 'hide',
                width: 600,
                minWidth: 350,
                height: 550,
                layout: {
                    type: 'border',
                    padding: 5
                        },
                items:[
                        listView, 
                    {                           
                    region: 'center',
                    //xtype: 'tabpanel',
                    minheight: 350,
                    items: [{
                        //title: 'Bogus Tab',
                        xtype : 'image',
                        id : 'displayimage',
                        width: 320,
                        height: 240,
                            }]
                    },
                    {
                    region: 'north',
                    margin : "5 0 5 0",
                    //xtype: 'tabpanel',
                    minheight: 350,
                    items: [dr]
                    }]

            });

enter image description here

问题

如何在窗口中心对齐displayimage?我试过 align : 'center',但不起作用。请帮助解决这个愚蠢的问题,非常感谢!
除了使用边距或填充之外有任何想法。这种方法不好

最新动态

var Printtoolbar = Ext.create('Ext.toolbar.Toolbar',{
        items:[
        {text: 'Print',
        id: 'btnPrint',
        tooltip: 'Print This Image !',
        iconCls: 'print'
        }
        ]
    })
    var dr = Ext.create('Ext.FormPanel', {
        width:650,
        bodyPadding: '5px 5px 0',
        frame: true,
        layout: {
            type: 'vbox'
        },
        items: [{
                    xtype: 'container',
                    layout: {
                        type: 'hbox',
                        //align: 'stretch',
                        padding:'0 0 10 0'
                    },
                    defaults: {
                        flex: 1
                    },
                        items:[startdt,enddt]
                    },
                    {
                    xtype: 'container',
                    layout: {
                        type: 'hbox',
                        align: 'center',
                        padding:'0 0 10 0'
                            },//layout
                    defaults: {
                        flex: 1
                             },//default
                        items:[cmbVehicle,{
                            //able to add 1 more items beside combobox
                            }]//items
                    },//container
                    {
                            xtype: 'button',
                            id : 'btnShowImage',
                            text : 'Show Image On List',
                            scale   : 'large',
                            width : 200,
                            margin : '0 0 0 180',   
                    }
                ]
    });

var listView = Ext.create('Ext.grid.Panel', {
        region: 'west',
        id : 'imagelist',
        title: 'Select Image',
        width: 200,
        split: true,
        collapsible: true,
        floatable: false,
        title:'Select Image',
        store: ImgStore,
        multiSelect: false,
        viewConfig: {
            emptyText: 'No images to display'
        },

        columns: [
            {
            text: 'Date Time Uploaded',
            //xtype: 'datecolumn',
            //format: 'Y-m-d H:i:s',
            flex: 65,
            width: 100,
            dataIndex: 'PicUploadedDateTime'
        }]
    });
win = Ext.create('widget.window', {
            title: 'View Image',
            closable: true,
            style:{
                            'display': 'table-cell',
                            'vertical-align': 'middle'
                        },
            closeAction: 'hide',
            width: 600,
            minWidth: 350,
            height: 550,
            layout: {
                type: 'border',
                padding: 5
                    },
            items:[
                    listView, 
                {                           
                region: 'center',

                //xtype: 'tabpanel',
                minheight: 350,
                items: [Printtoolbar,{
                    //title: 'Bogus Tab',
                    xtype : 'image',
                    id : 'displayimage',
                    style: {
                                'display': 'block',
                                'margin': 'auto'
                            },
                    listeners: {
                        'render': function(img) {
                            img.up().setBodyStyle({
                                'display': 'table-cell',
                                'vertical-align': 'middle'
                                                });
                                                }
                                 },
                    width: 320,
                    height: 240,
                        }]
                },
                {
                region: 'north',
                margin : "5 0 5 0",
                //xtype: 'tabpanel',
                minheight: 350,
                items: [dr]
                }]

        });

最佳答案

只需配置图像和面板的“样式”属性。 图片:

{
    xtype : 'image',
    id : 'displayimage',
    width: 320,
    height: 240,
    style: {
        'display': 'block',
        'margin': 'auto'
    }
}

面板:

style:{
    'display': 'table-cell',
    'vertical-align': 'middle'
}

您还可以在图像的“渲染”监听器中设置面板样式:

Ext.getCmp('displayimage').on({
    'render': function(img) {
        img.up().setBodyStyle({
            'display': 'table-cell',
            'vertical-align': 'middle'
        });
     }
});

Screenshot

关于javascript - 如何在中心显示图像 - extjs 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14920869/

相关文章:

javascript - 一页上有多个 jQuery

java - 将变量从 Scriptlet 传递到 Javascript。

php - 获取输入路径以提交到 php 中的保管箱

java - 通过传递输入文本框中的参数,通过 jQuery AJAX 调用 Java EE REST 服务

javascript - 如何在 Sencha Touch 应用程序中实现自定义 Toast?

extjs - 如何取消 ExtJS 4.1 中 spinner 字段的事件?

javascript - 单击 iFrame 不会模糊 Ext Combobox

javascript - 使用 JavaScript/JQuery 切换隐藏的工具提示

JQuery 不会将任何内容传递给 ASP.NET Controller

php - 提交 AJAX 表单后创建自定义确认框