在 BlackBerry ListField 中绘制边框
我已经使用自定义 ListFieldCallback 为我的 BlackBerry 应用程序实现了 ListField。它运行良好,但有两个问题:
首先,我指定的位图仅在第一行中绘制。它没有在后面的任何其他行中绘制(但是文本绘制得很好)。
其次,我想在当前选定的 ListField 元素周围绘制蓝色边框。为此,我重写了 ListField 的 drawFocus() 以使其不包含任何内容,并且还在 navigationMovement() 方法上将 ListField 设置为 invalidate()。边框绘制在第一行,而不是其他任何行。谁能弄清楚为什么吗?这是我的相关代码:
ListField 实例化:
ListField lf = new ListField() {
protected void drawFocus(Graphics graphics, boolean on) {
}
protected boolean navigationMovement(int dx, int dy,
int status, int time) {
this.invalidate(this.getSelectedIndex());
return super.navigationMovement(dx, dy, status, time);
}
protected boolean navigationClick(int status, int time) {
return true;
}
};
lf.setEmptyString("No items.", DrawStyle.HCENTER);
_callback = new ListCallback(vector, Bitmap
.getBitmapResource("image.png"));
lf.setCallback(_callback);
add(lf);
lf.setSize(vector.size());
自定义 ListField 回调:
if (index == list.getSelectedIndex()) {
g.setColor(0x4096cc);
g.drawBitmap(5, (bitmapHeight - fontHeight) * 2,
_bitmap.getWidth(), _bitmap.getHeight(), _bitmap, 0, 0);
g.drawText(text, _bitmap.getWidth() + 15,
y, 0, w);
g.drawRect(0, 0, list.getWidth(), list.getRowHeight());
} else {
g.setColor(0x4096cc);
g.drawBitmap(5, (bitmapHeight - fontHeight) * 2,
_bitmap.getWidth(), _bitmap.getHeight(), _bitmap, 0, 0);
g.drawText(text, _bitmap.getWidth() + 15,
y, 0, w);
}
谢谢!
I have implemented a ListField for my BlackBerry application with a custom ListFieldCallback. It is working well, with the exception of two problems:
First, my specified bitmap is only drawing in the first row. It is not drawing in any other row following (the text draws fine, however).
Second, I want to draw a blue border around the currently selected ListField element. To do this, I have overridden the drawFocus() of the ListField to contain nothing and I have also set the ListField to invalidate() on the navigationMovement() method. The border is being drawn on the first row, but not any others. Can anyone figure out why? Here is my relevant code:
The ListField instantiation:
ListField lf = new ListField() {
protected void drawFocus(Graphics graphics, boolean on) {
}
protected boolean navigationMovement(int dx, int dy,
int status, int time) {
this.invalidate(this.getSelectedIndex());
return super.navigationMovement(dx, dy, status, time);
}
protected boolean navigationClick(int status, int time) {
return true;
}
};
lf.setEmptyString("No items.", DrawStyle.HCENTER);
_callback = new ListCallback(vector, Bitmap
.getBitmapResource("image.png"));
lf.setCallback(_callback);
add(lf);
lf.setSize(vector.size());
The custom ListField Callback:
if (index == list.getSelectedIndex()) {
g.setColor(0x4096cc);
g.drawBitmap(5, (bitmapHeight - fontHeight) * 2,
_bitmap.getWidth(), _bitmap.getHeight(), _bitmap, 0, 0);
g.drawText(text, _bitmap.getWidth() + 15,
y, 0, w);
g.drawRect(0, 0, list.getWidth(), list.getRowHeight());
} else {
g.setColor(0x4096cc);
g.drawBitmap(5, (bitmapHeight - fontHeight) * 2,
_bitmap.getWidth(), _bitmap.getHeight(), _bitmap, 0, 0);
g.drawText(text, _bitmap.getWidth() + 15,
y, 0, w);
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有所有代码,很难准确判断,但是您的 drawText 调用使用 y 值,而其他调用则不使用 y 值,因此这解释了为什么它们都在同一位置绘制。
Hard to tell exactly without all the code, but your drawText call uses the y value while the other calls don't, so that explains why they're all drawing at the same spot.