【问题标题】:Items superimposed on an image extjs叠加在图像上的项目 extjs
【发布时间】:2017-02-17 17:34:12
【问题描述】:

我有一个侧边菜单,第一项是图像,然后是触发字段和选项卡面板。问题是当您访问屏幕时,触发字段和选项卡面板在图像上方,当单击选项卡面板时,项目会在屏幕上进行调整。打开屏幕时字段对齐如何做到这一点?

https://gyazo.com/9d896a46d800812e23df68aaf5e804b9

【问题讨论】:

    标签: extjs extjs6


    【解决方案1】:

    没有看到代码很难确定,但这可能与图像在执行初始布局时尚未加载的事实有关。如果您知道图像的尺寸,可以通过设置高度来快速解决此问题。

    这也可能与您使用的布局有关 - 我会为此推荐 vbox。

    在我的示例中,我在 url 中包含一个随机数以确保它没有被缓存:

    Ext.define('MyApp.view.Main',{
        extend: 'Ext.panel.Panel',
        alias: 'widget.main',
        layout:{
            type:'vbox'
        },
        items:[
            {
                xtype:'image',
                height:92,
                width:'auto',
                src:'https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png?'+Math.random()
            },
            {
                xtype:'combo',
                store:['A','B','C']
            },
            {
                xtype:'tabpanel',
                flex:1,
                width:'100%',
                items:[
                    {
                        title:'Test',
                        html:'foo'
                    }
                ]
            }
        ]
    })
    

    为了使图像宽度适合父面板,您可以使用 minWidth 和 minHeight 代替:

    Ext.define('MyApp.view.Main',{
        extend: 'Ext.panel.Panel',
        alias: 'widget.main',
        layout:{
            type:'vbox'
        },
        items:[
            {
                xtype:'image',
                minHeight:92,
                minWidth:272,
                width:'100%',
                src:'https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png?'+Math.random()
            },
            {
                xtype:'combo',
                store:['A','B','C']
            },
            {
                xtype:'tabpanel',
                flex:1,
                width:'100%',
                items:[
                    {
                        title:'Test',
                        html:'foo'
                    }
                ]
            }
        ]
    });
    

    或者您可以使用调整大小的侦听器:

    Ext.define('MyApp.view.Main',{
        extend: 'Ext.panel.Panel',
        alias: 'widget.main',
        layout:{
            type:'vbox'
        },
        items:[
            {
                xtype:'image',
                width:'100%',
                src:'https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png?'+Math.random(),
                listeners:{
                    resize:function(){
                        //ratio = originalWidth/originalHeight;
                        var ratio = 272/92;
                        this.setHeight(this.getWidth()/ratio)
                    }
                }
            },
            {
                xtype:'combo',
                store:['A','B','C']
            },
            {
                xtype:'tabpanel',
                flex:1,
                width:'100%',
                items:[
                    {
                        title:'Test',
                        html:'foo'
                    }
                ]
            }
        ]
    });
    

    【讨论】:

    • 感谢帮助,确实是图片的高度,设置固定尺寸后解决了问题,但是现在,通过增加vbox的宽度,图像没有重新调整尺寸,无论如何修复它?
    • 我已经用更多示例更新了我的答案。
    猜你喜欢
    • 2023-03-07
    • 2014-02-19
    • 2014-11-14
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 2021-01-28
    • 2017-08-21
    相关资源
    最近更新 更多