Java 修改LabelField(blackberry)的大小
类下面是自定义标签字段,它将位图绘制为其背景。Im覆盖GetPreferedWidth和getpreferredheight,这不会设置我的字段的高度和宽度吗?当前未正确设置宽度和高度 谢谢Java 修改LabelField(blackberry)的大小,java,blackberry,Java,Blackberry,类下面是自定义标签字段,它将位图绘制为其背景。Im覆盖GetPreferedWidth和getpreferredheight,这不会设置我的字段的高度和宽度吗?当前未正确设置宽度和高度 谢谢 public class TimerLabelField extends LabelField { private int colour; private Bitmap backgroundBitmap; public TimerLabelField(Obj
public class TimerLabelField extends LabelField {
private int colour;
private Bitmap backgroundBitmap;
public TimerLabelField(Object text, long style, Font font, int colour,
Bitmap backgroundBitmap) {
super(text, style);
this.colour = colour;
this.backgroundBitmap = backgroundBitmap;
}
protected void paint(Graphics graphics) {
if(backgroundBitmap != null){
graphics.drawBitmap(0, 0, this.backgroundBitmap.getWidth(), this.backgroundBitmap.getHeight(), this.backgroundBitmap, 0, 0);
}
graphics.setColor(this.colour);
super.paint(graphics);
}
public int getPreferredWidth()
{
return this.backgroundBitmap.getWidth();
}
public int getPreferredHeight()
{
return this.backgroundBitmap.getHeight();
}
您还应该覆盖布局(整数宽度、整数高度):
protected void layout(int width, int height) {
super.layout(width, height);
setExtent(Math.min(width, this.BackgroundBitmap.getWidth()), Math.min(height, this.Backgroundbitmap.getHeight());
}