【发布时间】:2015-10-28 19:56:04
【问题描述】:
我正在尝试制作可触摸的图像,当我通过设备上的可触摸按钮滚动它时可以聚焦这是我的可触摸图像代码:
class TouchBitmapField extends BitmapField {
Bitmap bitmap;
boolean second;
int width;
public TouchBitmapField(Bitmap startBitmap, long style, int width, boolean second) {
super(startBitmap, style);
this.second = second;
bitmap = startBitmap;
this.width = width;
}
protected void drawFocus(Graphics g, boolean on){
g.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true );
if(on){
drawHighlightRegion(g, Field.HIGHLIGHT_FOCUS, on, width-(bitmap.getWidth()/2), 0, bitmap.getWidth(), bitmap.getHeight());
}
paint(g);
}
protected boolean touchEvent(TouchEvent message) {
if (TouchEvent.CLICK == message.getEvent()) {
FieldChangeListener listener = getChangeListener();
if (null != listener)
listener.fieldChanged(this, 1);
}
return super.touchEvent(message);
}
}
但问题是只有图像的透明部分可以聚焦,我在创建 TouchBitmapField 之前调整了这个位图,你可能知道调整位图删除透明部分并将其替换为黑色。我尝试使用 http://www.patchou.com/2010/10/resizing-transparent-bitmaps-with-the-blackberry-jde/ 这个类来调整图像大小,但我的屏幕上有 25 张图像,而且效率低下。知道如何在图像上制作边框吗?在drawFocus(Graphics g, boolean on) 方法中绘制边框的任何有效方法?
【问题讨论】:
标签: blackberry java-me