blackberry:如果将另一个字段绘制为相同的x坐标,则获取字段焦点时出现问题
我有一个AbsoluteFieldManager,它在一个水平行中包含多个字段,切换焦点效果很好。现在我需要在与上面的左字段相同的水平位置添加另一个字段。这样做时,我无法再聚焦第一个字段。屏幕应如下所示:blackberry:如果将另一个字段绘制为相同的x坐标,则获取字段焦点时出现问题,blackberry,Blackberry,我有一个AbsoluteFieldManager,它在一个水平行中包含多个字段,切换焦点效果很好。现在我需要在与上面的左字段相同的水平位置添加另一个字段。这样做时,我无法再聚焦第一个字段。屏幕应如下所示: ________________________ | ____ ____ ____ | | |_f1_| |_f2_| |_f3_| | | ____ | | |_f4_| | with f4 added here, f1
________________________
| ____ ____ ____ |
| |_f1_| |_f2_| |_f3_| |
| ____ |
| |_f4_| | with f4 added here, f1 isn't focusable, once it has
|______________________| lost focus.
如果你有办法解决这个问题,我会很感激的。以下是我目前的代码:
测试屏幕:
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.container.AbsoluteFieldManager;
import net.rim.device.api.ui.container.MainScreen;
public class TestScreen extends MainScreen {
int screenY = Display.getWidth();
int screenX = Display.getHeight();
public TestScreen() {
AbsoluteFieldManager manager = new AbsoluteFieldManager();
TestField f1 = new TestField(50, 50, true);
TestField f2 = new TestField(50, 50, true);
TestField f3 = new TestField(50, 50, true);
TestField f4 = new TestField(50, 50, true);
TestField f5 = new TestField(50, 50, false);
manager.add(f1, 0, 0);
manager.add(f2, 60, 0);
manager.add(f3, 120, 0);
manager.add(f4, 180, 0);
// this works fine:
// manager.add(f5, 1, 80);
// this not:
manager.add(f5, 0, 80);
add(manager);
}
}
测试字段:
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
public class TestField extends Field {
boolean isFocusable;
int width, height;
int bgColorUnfocused, bgColorFocused;
public TestField(int width, int height, boolean isFocusable){
this.width=width;
this.height=height;
this.isFocusable=isFocusable;
bgColorUnfocused= 0xC0C0C0;
bgColorFocused = 0x3956F7;
}
protected void layout(int w, int h) {
setExtent(width, height);
}
public boolean isFocusable() {
return isFocusable;
}
protected void paint(Graphics g) {
g.setColor(isFocus() ? bgColorFocused : bgColorUnfocused);
g.fillRect(0, 0, width, height);
}
}
TestApp:
import net.rim.device.api.ui.UiApplication;
public class TestApp extends UiApplication{
TestScreen screen = new TestScreen();
public static void main(String args[]){
TestApp app = new TestApp();
app.enterEventDispatcher();
}
public TestApp(){
pushScreen(screen);
}
}
由于AbsoluteFieldManager不确定您将项目放置在何处,因此它不知道在使用滚轮时发送焦点的顺序。如果您想管理此操作,请使用AFM的ovveride
nextFocus(int,int)
,以便您可以根据焦点的位置和预期移动的位置指定谁获得焦点
更多详情,请参阅)