固定大小的Blackberry VerticalFieldManager:滚动问题
我正在尝试一个带有固定标题(带有一些字段的管理器)和可滚动内容(自定义字段列表)的全屏UI。其想法是模拟一种可滚动列表 为此,我制作了一个定制的VerticalFieldManager,它接受maxHeight(屏幕高度-页眉高度) 我遇到了以下问题:固定大小的Blackberry VerticalFieldManager:滚动问题,blackberry,Blackberry,我正在尝试一个带有固定标题(带有一些字段的管理器)和可滚动内容(自定义字段列表)的全屏UI。其想法是模拟一种可滚动列表 为此,我制作了一个定制的VerticalFieldManager,它接受maxHeight(屏幕高度-页眉高度) 我遇到了以下问题: 滚动箭头不会显示(永远) 在OS4.7(Storm)上,我可以滚动到最后一项的下方,直到屏幕上除了标题外没有任何内容 我的代码需要使用JDE4.2.1和4.7进行编译,并在Pearl和Storm上运行。(最坏情况下,我可以有两个版本的这个类)
- 滚动箭头不会显示(永远)
- 在OS4.7(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);
}
}
/**
*自定义类,因此我们可以设置最大高度(以保持标题可见)
*/
类myVerticalFieldManager扩展了VerticalFieldManager{
私有int maxHeight=0;
myVerticalFieldManager(内部最大高度){
超级(
//这是Storm上的“空滚动区域”
//但是如果你不把它放在其他操作系统上,垂直管理器根本不会滚动。
垂直滚动
|Manager.VERTICAL\u滚动条
);
最大高度=_最大高度;
}
受保护的空位子布局(整数宽度、整数高度){
super.sublayout(宽度,getPreferredHeight());
setExtent(宽度,getPreferredHeight());
}
public int getPreferredWidth(){
返回Graphics.getScreenWidth();
}
/**
*允许管理员使用所有给定高度。(vs自动高度)
*/
公共布尔值forceMaxHeight=false;
public int getPreferredHeight(){
如果(forceMaxHeight)返回maxHeight;
int m=super.getPreferredHeight();
如果(m>maxHeight)m=maxHeight;
返回m;
}
////////////////////////////////////////////////////////////////////////////
受保护的布尔值IsUpArrowShowed(){
//TODO:似乎不工作(4.2.1 emulator和4.5设备)。(使用良好的返回值调用,但未绘制箭头)
int i=getFieldWithFocusIndex();
//跟踪(“显示的是向上箭头”+i);
返回i>0;
//注意:algo不正确,因为当没有隐藏字段时,向上箭头将可见。
//但还不算太糟,所以用户“知道”他可以上去。
}
受保护的布尔值IsDownArrowShowed(){
int i=getFieldWithFocusIndex();
返回i
欢迎任何帮助。所以
我为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);
}
}
实现ScrollChangeListener
//在构造函数中:
setScrollListener(空);
setScrollListener(此);
私有布尔MY\u CHANGING\u SCROLL=false;
公共无效滚动已更改(管理器管理器、int-newhorizontalcoll、int-newVerticalScroll){
如果(!我的更改滚动){
MY_CHANGING_SCROLL=真;
myCheckVerticalScroll();
MY_CHANGING_SCROLL=false;
}
}
受保护的整型myMaxVerticalScrollPosition(){
int vh=getVirtualHeight();
inth=getHeight();
如果(vhm){
i=m;
设置垂直卷轴(i);
}
}
我仍在寻找滚动箭头问题的解决方案。。。
如果有人有了主意…您可以使用方法
setBanner()
而不是添加标题。然后,您可以向屏幕添加默认的VerticalFieldManager
,它将正常滚动,但不会隐藏标题。请注意,main屏幕
代表管理器是一个垂直滚动管理器
,因此您可能不需要第二个vfm
HorizontalFieldManager hfm = new HorizontalFieldManager();
setBanner(hfm)
add(new ButtonField("Hello 1");
add(new ButtonField("Hello 2");
…嘿,我用一个包含图像和标题的HorizontalFieldManager做了同样的事情
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);
setTitle()的问题在于lib在标题区域下添加了一个非常难看的4-5px阴影。我承认:我没有尝试setBanner()。我发现可以用一种更简单的方法得到相同的结果:-创建带有NO_SCROLL标志的屏幕。(我错过了);-将标题添加为普通字段;-添加一个包含所有内容的vfm;-->箭头将显示,标题将停留在其应位于的位置。此外,在“setTitle()区域”下没有丑陋的阴影