我尝试创建一个全屏UI,其中包括一个固定头部(一个带有一些字段的管理器)和可滚动内容(自定义字段列表)。想法是模拟一种可滚动列表。
为此,我制作了一个自定义的VerticalFieldManager,它接受一个maxHeight(屏幕高度-标题高度)。
我遇到了以下问题:
- 滚动箭头从未显示过 - 在OS 4.7(Storm)上,我可以滚动到最后一个项目之下,直到屏幕上只剩下标题。
我的代码需要使用JDE 4.2.1和4.7进行编译,并在Pearl和Storm上运行。 (最坏的情况下,我可以有两个版本的这个类)
我怀疑这两个问题有关。 我可能做错了什么。 我查看了一些示例/论坛,并始终发现类似的解决方案/代码。 你们能告诉我我做错了什么吗?
为此,我制作了一个自定义的VerticalFieldManager,它接受一个maxHeight(屏幕高度-标题高度)。
我遇到了以下问题:
- 滚动箭头从未显示过 - 在OS 4.7(Storm)上,我可以滚动到最后一个项目之下,直到屏幕上只剩下标题。
我的代码需要使用JDE 4.2.1和4.7进行编译,并在Pearl和Storm上运行。 (最坏的情况下,我可以有两个版本的这个类)
我怀疑这两个问题有关。 我可能做错了什么。 我查看了一些示例/论坛,并始终发现类似的解决方案/代码。 你们能告诉我我做错了什么吗?
/**
* 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);
}
}
欢迎任何帮助。