2012-08-16 26 views
1

以下代碼顯示了我在當前應用中使用的某個視圖的定義,這意味着此視圖很容易創建,並且應該在顯示時將其添加到Ext.Viewport面板可滾動時的固定高度?

它的結構非常簡單:有一個與下方的面板工具欄,其中可以包含任何其他組件,如按鈕,面板等

但是:我的問題是,既然我添加的配置滾動:真(如下圖所示),我還必須爲該面板設置固定的高度(在這種情況下爲300)。如果我沒有設置高度,面板中的所有組件都不會顯示。

更糟糕的問題是,我不知道什麼高度我應該在這裏設置,因爲我的應用程序當然應該適用於不同屏幕尺寸(iPhone/iPad/...)的不同設備。

所以我想要實現的是工具欄下的面板使用完全可用的高度,並且在內容比自身高度高的情況下它應該是可滾動的。希望你能幫助我與:-)

Ext.define('PV.view.Menu', { 
    extend: 'Ext.Panel', 

    xtype: 'menu', 

    config: { 
     items: [ 
      { 
       xtype: 'toolbar', 
       title: 'My Menu' 
      }, 
      { 
       xtype: 'panel', 
       scrollable: true, 
       height: 300, 
       items: [ 
        { 
         xtype: 'button', 
         text: 'Navigate to view 1 >', 
         action: 'nav-to-view1' 
        }, 
        { 
         xtype: 'button', 
         text: 'Navigate to view 2 >', 
         action: 'nav-to-view2' 
        }, 
        { 
         html: 'A lot of text<br />A lot of text<br />A lot of text<br />A lot of text<br />A lot of text' 
        } 
       ] 
      } 
     ] 
    } 
}); 

回答

0

您正在尋找layout:'fit',以及(可能)minHeight

http://docs.sencha.com/touch/2-0/#!/api/Ext.Component-cfg-minHeight

http://docs.sencha.com/touch/2-0/#!/api/Ext.layout.Fit

config: { 
    layout:'fit', 
    items: [ 
     { 
      xtype: 'toolbar', 
      title: 'My Menu' 
     }, 
     { 
      xtype: 'panel', 
      scrollable: true, 
//    height: 300, 
      items: [ 
       { 
        xtype: 'button', 
        text: 'Navigate to view 1 >', 
        action: 'nav-to-view1' 
       }, 
       { 
        xtype: 'button', 
        text: 'Navigate to view 2 >', 
        action: 'nav-to-view2' 
       }, 
       { 
        html: 'A lot of text<br />A lot of text<br />A lot of text<br />A lot of text<br />A lot of text' 
       } 
      ] 
     } 
    ] 
} 
+0

感謝您的快速回答! :-) 我嘗試了'layout:fit'的建議,但它沒有奏效。您可以在我創建的senchafiddle.com上的示例中看到它:http://www.senchafiddle.com/#ouwAK。使用'layout:fit',整個佈局看起來很糟糕:-( – Schildi 2012-08-16 19:29:47

+0

而minHeight的定義並不能真正解決我認爲不同屏幕尺寸的問題,是嗎?我的意思是,當我將minHeight定義爲iPhone的高度,iPad上的面板太短**當我將minHeight定義爲iPad的高度時,面板太長**在iPhone上:-( – Schildi 2012-08-16 19:31:00

+0

我感到困惑......小提琴,在工具欄中添加了一個擴展塢以及更多文本,正是我所瞭解的您正在尋找的內容?http://www.senchafiddle.com/#ouwAK#PAOSf – Alex 2012-08-17 17:10:14