我正嘗試使用修正標題(具有某些字段的管理器)和可滾動內容(自定義字段列表)的全屏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);
}
}
任何幫助,歡迎。
我發現你可以有通過一個簡單的方法相同結果的HorizontalFieldManager做同樣的事情: - 用NO_SCROLL標誌創建屏幕。 (我錯過了); - 將標題添加爲普通字段; - 添加一個vfm與你所有的東西; - >箭頭將顯示,標題將保留在應該的位置。另外,在setTitle()區域「setTitle()area」 – Loda 2009-11-10 15:03:03