在sencha touch 2中更改方向时更改尺寸轮播

时间:2013-07-24 08:35:19

标签: extjs sencha-touch touch orientation carousel

我把旋转木马放在容器中。

  • 在portrail模式下,我设置高度150,图像在旋转木马中全屏显示。 但是当我改为横向时,图像的两侧有两个白色空白。

  • 我希望通过设置另一个高度值来改变尺寸轮播。你能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

您需要捕获orientationchange事件 (http://docs.sencha.com/touch/2.0.2/#!/api/Ext.viewport.Default-event-orientationchange)并在捕获它时调用一个可以调整容器大小的函数。

您可以尝试这样的事情:

Ext.Viewport.on('orientationchange', 'handleOrientationChange', this);

然后在handle函数中设置所需的组件大小:

handleOrientationChange: function(){
    Ext.getCmp('idOfMyContainer').setWidth('480px'); //or setHeight() depending on the real problem
}

您还可以根据屏幕的实际大小设置宽度和高度,您可以通过调用这些方法获得。请注意,方向更改不会影响这些的返回值,因此您需要手动切换它:

Ext.Viewport.getWindowWidth();
Ext.Viewport.getWindowHeight()