【问题标题】:Auto Scroll Vertical Field Manager自动滚动垂直字段管理器
【发布时间】:2013-03-27 10:35:32
【问题描述】:

我开发了一个带有简单聊天功能的 BlackBerry 应用程序。当用户单击Send 时,聊天消息出现在Vertical Field Manager (VFM) 中。用户可以发送多条消息。发送的每条新消息都显示在旧消息下方。这样,Vertical Field Manager 的大小就会不断增加。我创建了一个可滚动的VFM,因此用户可以通过向下滚动查看最新发送的消息。 是否可以在发送消息时自动滚动到 VFM 底部,以便将焦点设置在最后一条消息上?

我曾尝试致电vfm.setVerticalScroll(int y);LabelField chat1 = new LabelField( "Hi", Field.FIELD_LEFT|Field.FOCUSABLE);,但这无济于事。请指导。

vr2 = 垂直现场经理

chat1 = 聊天消息添加到 VFM


编辑:我在 StackOverFlow 上看到了 this 链接,并在我的代码中应用了如下更改:

vr2.setVerticalScroll(vr2.getVirtualHeight());
LabelField chat1 = new LabelField( "Hi", Field.FIELD_LEFT)
{
 protected void applyTheme(Graphics g, boolean arg1) 
     {
        g.setColor(Color.DEEPSKYBLUE);
        super.applyTheme(g, arg1);
     }
};
Font myFont = Font.getDefault().derive(Font.BOLD, 8, Ui.UNITS_pt);
chat1.setFont(myFont);
chat1.setBorder( leftBorder );
chat1.setMargin( 0, 0, -15, 0);
vr2.setBorder(bdr);
vr2.add(chat1);
Field f;
int i = vr2.getFieldCount();
f = vr2.getField(i-1);  //getFieldCount, gets total number of fields
f.setFocus();

这使我非常接近我正在寻找的解决方案。 VFM 滚动低于正常值。但是,它不是定位到 VFM 中的最后一条消息,而是每次滚动到倒数第二条消息。为什么会这样?它应该滚动到 VFM 中的最后一条消息;就在 VFM 的底部。

【问题讨论】:

    标签: user-interface blackberry scroll autoscroll


    【解决方案1】:

    我终于设法解决了这个问题。如果还有其他人遇到这样的问题,我会分享我的答案。虽然我上面问题中的编辑帮助我更接近解决方案,但我发现错误在于没有在正确的位置调用vr2.setVerticalScroll(vr2.getVirtualHeight());

    详情请查看stackoverflow上的this问题和黑莓支持论坛上的this。解决方法如下:

    LabelField chat1 = new LabelField( "Hi", Field.FIELD_LEFT)
    {
     protected void applyTheme(Graphics g, boolean arg1) 
         {
            g.setColor(Color.DEEPSKYBLUE);
            super.applyTheme(g, arg1);
         }
    };
    
    Font myFont = Font.getDefault().derive(Font.BOLD, 8, Ui.UNITS_pt);
    chat1.setFont(myFont);
    chat1.setBorder( leftBorder );
    chat1.setMargin( 0, 0, -15, 0);
    vr2.setBorder(bdr);
    vr2.setVerticalScroll(vr2.getVirtualHeight()); //scrolls to the bottom of the vertical field manager
    vr2.add(chat1);
    Field f;
    int i = vr2.getFieldCount();
    f = vr2.getField(i-1);  //getFieldCount, gets total number of fields
    f.setFocus(); //sets focus on the newly added field
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-28
      • 2016-10-06
      • 1970-01-01
      • 1970-01-01
      • 2021-11-13
      相关资源
      最近更新 更多