我有一个 VerticalFieldManager,它呈现一个白色圆角矩形。
这是代码:
VerticalFieldManager _vfmBackground = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL |
Manager.NO_VERTICAL_SCROLLBAR | Manager.USE_ALL_WIDTH){
public void paint(Graphics graphics)
{
graphics.clear();
graphics.setColor(Color.WHITE);
graphics.fillRoundRect(10, 10,460, 400, 25,25 );
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = (Display.getWidth());
int displayHeight = (Display.getHeight());
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
然后我创建一个名为 BaseHeaderBlueScreen 的自定义管理器类,它呈现一个蓝色矩形:
public void paint(Graphics graphics)
{
graphics.clear();
graphics.setColor(610212);
graphics.fillRect(20, 0, Display.getWidth(), Display.getHeight());
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = (Display.getWidth()-40);
int displayHeight = ((Display.getHeight()/2))-90;
super.setExtent( displayWidth, displayHeight);
}
最后,我使用白色圆角矩形将该自定义管理器添加到 VerticalFieldManager:
BaseHeaderBlueScreen _vhbs = new BaseHeaderBlueScreen(textTop, textBottom, 0);
_vhbs.setPadding(20,30,0,0);
_vfmBackground.add(_vhbs);
这就是蓝色矩形在白色矩形内的显示方式。
但这就是蓝色矩形当前的显示方式(请注意其左侧的灰色空间):
我应该如何正确渲染蓝色矩形(没有左侧灰色边框)?
最佳答案
我认为您只是不必要地调用Graphics.clear()
。 clear()
旨在用当前设置为背景色的任何颜色填充图形区域。通常,您会像这样使用clear()
:
public void paint(Graphics g) {
g.setBackgroundColor(Color.GRAY);
// calling clear makes the background gray
g.clear();
// now draw some text
g.setColor(Color.WHITE);
g.drawText("hello", 20, 40);
}
Clears the entire graphics area to the current background color. Note that global alpha is not applied in this case.
但是,您在进行任何其他调用之前先调用 clear()
。
因此,只需删除对 clear()
的两个调用即可(尽管导致此特定问题的是 BaseHeaderBlueScreen.paint()
中的调用)。
关于java - 添加到 BlackBerry 中的 VerticalFieldManager 后,自定义管理器未正确呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13723049/