2009-11-02 62 views
3

我正嘗試使用修正標題(具有某些字段的管理器)和可滾動內容(自定義字段列表)的全屏UI。這個想法是模仿一種可滾動的列表。具有固定大小的黑莓VerticalFieldManager:滾動問題

爲此,我製作了一個自定義VerticalFieldManager,它接受maxHeight(屏幕高度 - 標題高度)。

我有以下問題:

  • 滾動箭頭顯示不出來(曾經)
  • 在OS 4.7(風暴),我可以滾動下的最後一個項目,直到有沒有我屏幕,但標題。

我的代碼需要編譯的JDE 4.2.1 & 4.7和珍珠和風暴運行。 (最壞的情況下,我可以有這個類的兩個版本)

我懷疑這兩個問題是相關的。我可能做錯了什麼。我看了幾個例子/論壇,總是找到類似的解決方案/代碼。 你們能告訴我我做錯了什麼嗎?

/** 
* custom class, so we can set a max height (to keep the header visible) 
*/ 
class myVerticalFieldManager extends VerticalFieldManager{ 
private int maxHeight = 0; 

myVerticalFieldManager(int _maxHeight){ 
    super(
    //this provoc an "empty scrollable zone" on Storm 
    // but if you don't put it, on other OS, the vertical manager does not scroll at all. 
    Manager.VERTICAL_SCROLL 

    | Manager.VERTICAL_SCROLLBAR 
    ); 
    maxHeight = _maxHeight; 
} 


protected void sublayout(int width, int height){ 
     super.sublayout(width, getPreferredHeight()); 
     setExtent(width, getPreferredHeight()); 
} 

public int getPreferredWidth() { 
    return Graphics.getScreenWidth(); 
} 

/** 
* allow the manager to use all the given height. (vs auto Height) 
*/ 
public boolean forceMaxHeight = false; 
public int getPreferredHeight() { 
    if (forceMaxHeight) return maxHeight; 
    int m = super.getPreferredHeight(); 
    if (m > maxHeight) m = maxHeight; 
    return m; 
}  

//////////////////////////////////////////////////////////////////////////// 

protected boolean isUpArrowShown(){ 
    //TODO: does not seem to work (4.2.1 emulator & 4.5 device). (called with good return value but the arrows are not painted) 
    int i = getFieldWithFocusIndex(); 
    //Trace("isUpArrowShown " + i); 
    return i > 0; 
    // note: algo not correct, cause the up arrow will be visible event when no field are hidden. 
    //  but not so bad, so the user "know" that he can go up. 
} 

protected boolean isDownArrowShown(){ 
    int i = getFieldWithFocusIndex(); 
    return i < getFieldCount(); 
} 

//////////////////////////////////////////////////////////////////////////// 
// note : since 4.6 you can use 
// http://www.blackberry.com/developers/docs/4.6.0api/net/rim/device/api/ui/decor/Background.html 

public int myBackgroundColor = 0xffffff; 
protected void paint(Graphics g){ 
    g.setBackgroundColor(myBackgroundColor); 
    // Clears the entire graphic area to the current background 
    g.clear(); 
    super.paint(g); 
} 


} 

任何幫助,歡迎。

回答

4

所以,

我想出了這個解決方法上STORM 它的醜陋,不允許自定義ScrollChangeListener「空滾動區」的問題,但它的工作對珍珠&風暴

implements ScrollChangeListener 

//in constructor: 

    setScrollListener(null); 
    setScrollListener(this); 


private boolean MY_CHANGING_SCROLL = false; 
public void scrollChanged(Manager manager, int newHorizontalScroll, int newVerticalScroll){ 
    if (!MY_CHANGING_SCROLL){ 
    MY_CHANGING_SCROLL = true; 
    myCheckVerticalScroll(); 
    MY_CHANGING_SCROLL = false; 
    }  
} 


protected int myMaxVerticalScrollPosition(){ 
    int vh = getVirtualHeight(); 
    int h = getHeight(); 
    if (vh < h) return 0; // no scroll 
    return vh - h; // don't scroll lower than limit. 
} 

protected void invCheckVerticalScroll() { 
    int i = getVerticalScroll(); 
    int m = myMaxVerticalScrollPosition(); 
    if (i > m){ 
     i = m; 
     setVerticalScroll(i); 
    } 
} 

我仍在尋找滾動箭頭問題的解決方案... 如果有人有想法...

+2

我發現你可以有通過一個簡單的方法相同結果的Horizo​​ntalFieldManager做同樣的事情: - 用NO_SCROLL標誌創建屏幕。 (我錯過了); - 將標題添加爲普通字段; - 添加一個vfm與你所有的東西; - >箭頭將顯示,標題將保留在應該的位置。另外,在setTitle()區域「setTitle()area」 – Loda 2009-11-10 15:03:03

2

您可以使用方法setBanner()而不是dd爲您的標題。然後,您可以在屏幕上添加一個默認的VerticalFieldManager,它將正常滾動,但不會隱藏標題。請注意0​​代理經理是VerticalScrollManager,因此您可能不需要第二個vfm

HorizontalFieldManager hfm = new HorizontalFieldManager(); 
setBanner(hfm) 

add(new ButtonField("Hello 1"); 
add(new ButtonField("Hello 2"); 

...

+0

的問題中,您沒有醜陋的陰影,因爲lib在標題區域下添加了一個非常難看的4-5px陰影。我承認:我沒有嘗試setBanner()。 – Loda 2009-11-10 15:00:47

0

嘿,我使用了包含圖像和標題

header_img = Bitmap.getBitmapResource("header.png"); 
      title = new LabelField("Welcome",LabelField.FIELD_RIGHT); 
      header_manager = new HorizontalFieldManager() 
      { 
       protected void paint(net.rim.device.api.ui.Graphics graphics) 
        { 
         int y = this.getVerticalScroll();          
         graphics.drawBitmap(0, y, header_img.getWidth(), header_img.getHeight(), header_img, 0, 0); 
         graphics.setColor(Color.LEMONCHIFFON); 
         super.paint(graphics); 
        } 

        protected void sublayout(int maxWidth, int maxHeight) 
        {      
         super.sublayout(Display.getWidth(), 240); 

         Field field = title; 
         layoutChild(field, title.getWidth(), title.getHeight()); 
         setPositionChild(field, (Display.getWidth()/2) -10, 13); 
         setExtent(Display.getWidth(),55); 

        } 
      }; 
      header_manager.add(title);