【发布时间】:2017-02-17 17:34:12
【问题描述】:
我有一个侧边菜单,第一项是图像,然后是触发字段和选项卡面板。问题是当您访问屏幕时,触发字段和选项卡面板在图像上方,当单击选项卡面板时,项目会在屏幕上进行调整。打开屏幕时字段对齐如何做到这一点?
【问题讨论】:
我有一个侧边菜单,第一项是图像,然后是触发字段和选项卡面板。问题是当您访问屏幕时,触发字段和选项卡面板在图像上方,当单击选项卡面板时,项目会在屏幕上进行调整。打开屏幕时字段对齐如何做到这一点?
【问题讨论】:
没有看到代码很难确定,但这可能与图像在执行初始布局时尚未加载的事实有关。如果您知道图像的尺寸,可以通过设置高度来快速解决此问题。
这也可能与您使用的布局有关 - 我会为此推荐 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'
}
]
}
]
});
【讨论】: