具有固定大小的Blackberry VerticalFieldManager:滚动问题

时间:2009-11-02 09:28:19

标签: blackberry

我正在尝试使用带有修复标头(带有一些字段的管理器)和可滚动内容(自定义字段列表)的全屏UI。这个想法是模仿一种可滚动的列表。

为此,我制作了一个自定义的VerticalFieldManager,它接受maxHeight(屏幕高度 - 标题高度)。

我遇到了以下问题:

  • 滚动箭头未显示(永远)
  • 在操作系统4.7(风暴)上,我可以向下滚动最后一项,直到我的屏幕上没有任何内容,但标题。

我的代码需要使用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);
}


} 

欢迎任何帮助。

3 个答案:

答案 0 :(得分:4)

所以,

我为STORM上的“空可滚动区域”问题提供了此解决方法 它很丑陋并且不允许使用自定义ScrollChangeListener,但它正在使用Pearl&amp; amp;风暴

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);
    }
}

我还在寻找滚动箭头问题的解决方案...... 如果有人有想法......

答案 1 :(得分:2)

您可以使用方法setBanner()代替为标头添加。然后,您可以向屏幕添加默认VerticalFieldManager,它将正常滚动但不会隐藏标题。请注意,MainScreen代理经理是VerticalScrollManager,因此您可能不需要第二个vfm

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

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

...

答案 2 :(得分:0)

嘿,我使用包含图像和标题

的Horizo​​ntalFieldManager做了同样的事情
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);