【发布时间】:2009-07-07 16:19:31
【问题描述】:
我想将自定义按钮字段(屏幕截图上的星号)与水平管理器的中心对齐
HFM 的定义
final HorizontalFieldManager _navigation = new HorizontalFieldManager(HorizontalFieldManager.NO_VERTICAL_SCROLL | HorizontalFieldManager.FIELD_VCENTER | Field.USE_ALL_WIDTH)
{
protected void paint(Graphics graphics)
{
graphics.setGlobalAlpha(100);
int[] xInds = new int[]{0, getExtent().width, getExtent().width, 0};
int[] yInds = new int[]{0, 0, getExtent().height, getExtent().height};
final int[] cols = new int[]{Color.WHITE, Color.WHITE, color_computacenter_light_blue, color_computacenter_light_blue};
graphics.drawShadedFilledPath(xInds, yInds, null, cols, null);
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(maxWidth, maxHeight);
setExtent(maxWidth, navigation_vertical_manager_height);
}
};
自定义字段(部分)
public class NavigationButton extends Field
{
private String label;
Bitmap img;
int horizontalPadding = 4;
int verticalPadding = 10;
static int height;
static int weight;
ToolTip _tooltip;
public NavigationButton(String name, Bitmap img)
{
label = name;
this.img = img;
this.height = img.getHeight() + 4;
this.weight = img.getWidth() + 2;
}
public NavigationButton(String name, Bitmap img, long style)
{
super(style);
label = name;
this.img = img;
this.height = img.getHeight() + 4;
this.weight = img.getWidth() + 2;
}
protected void layout(int maxWidth, int maxHeight)
{
setExtent(maxWidth, maxHeight);
// setExtent(Math.min(weight, maxWidth), Math.min(height, maxHeight));
}
protected void paint(Graphics graphics)
{
// Draw background
graphics.setGlobalAlpha(255);
if(isFocus())
{
graphics.setColor(0x005AA1);
graphics.drawRoundRect(0 ,0 , weight + 1, height + 1, 2, 2);
}
if (img != null)
{
graphics.drawBitmap(0, 0 , img.getWidth(), img.getHeight(), img, 0, 0);
}
}
[...]
任何想法,我做错了什么?!
谢谢!
【问题讨论】:
-
您能否更明确地说明您想要实现的行为以及您实际看到的内容?截图不错!
-
嗨 Anthony,我添加了截图!
标签: java blackberry user-interface