我试图拥有一个带有修复标题(带有某些字段的管理器)和可滚动内容(自定义字段列表)的全屏用户界面。这个想法是模拟一种可滚动列表。
为此,我制作了一个接受 maxHeight(屏幕高度 - 标题高度)的自定义 VerticalFieldManager。
我遇到以下问题:
- 滚动箭头不显示(永远)
- 在 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);
}
}
欢迎任何帮助。
so,
我为 STORM 上的“空可滚动区域”问题提供了这个解决方法
它很丑陋,并且不允许自定义 ScrollChangeListener,但它可以在 Pearl & Storm 上使用
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);
}
}
我仍在寻找滚动箭头问题的解决方案......
如果有人有想法...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)