问题描述
我想生成一个 VerticalFieldManager
,有一个没有零保证金,所以我创建了一个 VerticalFieldManager
,然后用vfm.setMargin(10,10,10,10);在这之后,把一些领域( ButtonField字段
, ObjectChoiceField
)在里面。
I'd like to generate a VerticalFieldManager
that has a none-zero margin, so I create a VerticalFieldManager
, and then use vfm.setMargin(10, 10, 10, 10); after that, put some fields(buttonField
, ObjectChoiceField
) in it.
这似乎太简单了吧?但奇怪的事情发生了。当我集中到最后 ObjectChoiceField
和preSS空间来切换它的选择, ObjectChoiceField
消失了。
It seems too simple, right? but strange thing happens. When I focus to the last ObjectChoiceField
and press space to toggle choice of it, the ObjectChoiceField
disappeared.
怎么可能呢?这里是演示code,好心的人找到错误?
How can that be? here is the demo code, anyone kindly find the bug?
final class HelloWorldScreen extends MainScreen{
HelloWorldScreen() {
// just a demo to show the strange thing
String [] arr = {"a","b"};
for(int i = 0; i < 10; i++){
VerticalFieldManager vfm = new VerticalFieldManager(); // Field.USE_ALL_WIDTH
vfm.setMargin(10, 10, 10, 10);
ButtonField btn = new ButtonField(String.valueOf(i));
ObjectChoiceField ch = new ObjectChoiceField(String.valueOf(i), arr);
vfm.add(btn);
vfm.add(ch);
add(vfm);
}
}
}
编辑:所需的UI利润率的截图:
screenshot of desired UI margins:
推荐答案
这是奇怪的。
对于那些谁不跑你code的好处,发生的事情是,当你点击对象的选择领域,整个屏幕垂直滚动一点点。每个垂直滚动后,屏幕失去一路向下滚动至底部的能力。许多这样的操作后,最终很多该屏幕的下部是无法再访问。
For the benefit of those who don't run your code, what's happening is that when you click on the object choice fields, the whole screen is scrolling a little bit vertically. After each vertical scroll, the screen loses the ability to scroll all the way down to the bottom. After many such operations, eventually much of the lower part of this screen is no longer accessible.
我不知道为什么会这样。(看起来像一个黑莓的错误给我)
I don't know why this is happening. (looks like a BlackBerry bug to me)
我观察到的是,如果你把调用
What I observed is that if you take out the call to
vfm.setMargin(10, 10, 10, 10);
问题消失。
我建议,你用一种变通方法
May I suggest a workaround where you use
vfm.setPadding(10, 10, 10, 10);
呢?
我知道的缘的和的填充的是不一样的事情。然而,根据你的完整的UI设计(我看不到)的在这种情况下的,设置一个10像素的填充可能足以做你试图做的。
I know that margin and padding are not the same thing. However, depending on what your full UI design is (which I cannot see), in this case, setting a 10 pixel padding may be sufficient to do what you were trying to do.
更新:根据您所需的UI截图,我是能够生产出符合此解决办法。再次,它的不应的是这么多的工作,但这个额外的code为我工作:
Update: based on the screenshot of your desired UI, I was able to produce that with this workaround. Again, it shouldn't be this much work, but this additional code worked for me:
public class BugScreen extends MainScreen {
private static final int BG_COLOR = Color.LIGHTGRAY;
private static final int FG_COLOR = Color.WHITE;
private static final int BORDER_LINE_COLOR = Color.GRAY;
private static final int PAD = 10;
public BugScreen() {
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
getMainManager().setBackground(BackgroundFactory.createSolidBackground(BG_COLOR));
// this additional call ensures that when scrolling bounces, the area "behind"
// the normal visible area is ALSO of BG_COLOR
setBackground(BackgroundFactory.createSolidBackground(BG_COLOR));
// this will establish a thin gray padding on the screen's left/right sides
// NOTE: I seem to get drawing artifacts if I try to use this for ALL sides!
getMainManager().setPadding(0, PAD, 0, PAD);
String [] arr = {"a","b"};
for(int i = 0; i < 10; i++){
VerticalFieldManager vfm = new VerticalFieldManager(Field.USE_ALL_WIDTH) {
public int getPreferredWidth() {
return Display.getWidth() - 2 * PAD;
}
public void paint(Graphics graphics) {
int oldColor = graphics.getColor();
super.paint(graphics);
graphics.setColor(BORDER_LINE_COLOR);
// draw the (1-pixel wide) border size you would like.
graphics.drawRect(0, 0, getPreferredWidth(), getHeight());
graphics.setColor(oldColor);
}
};
vfm.setBackground(BackgroundFactory.createSolidBackground(FG_COLOR));
ButtonField btn = new ButtonField(String.valueOf(i));
ObjectChoiceField ch = new ObjectChoiceField(String.valueOf(i), arr);
vfm.add(btn);
vfm.add(ch);
// add a separator field to get thin gray margin between (vfm) fields
add(new MarginField());
add(vfm);
}
// add one last margin field at the bottom
add(new MarginField());
}
private class MarginField extends Field {
public MarginField() {
super(Field.USE_ALL_WIDTH);
}
public int getPreferredHeight() { return PAD; }
protected void paint(Graphics g) {
int oldColor = g.getColor();
g.setColor(BG_COLOR);
g.fillRect(0, 0, getWidth(), getPreferredHeight());
g.setColor(oldColor);
}
protected void layout(int width, int height) {
setExtent(width, getPreferredHeight());
}
}
}
这篇关于设置保证金VerticalFieldManager时,奇怪的事情发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!