在类下方是自定义标签字段,该字段将位图绘制为背景。我覆盖了getprefferedwidth和getpreferredheight,这会不会设置字段的高度和宽度?当前宽度和高度设置不正确
谢谢
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();
}
最佳答案
您还应该覆盖layout(int width, int height)
:
protected void layout(int width, int height) {
super.layout(width, height);
setExtent(Math.min(width, this.BackgroundBitmap.getWidth()), Math.min(height, this.Backgroundbitmap.getHeight());
}
关于java - 修改LabelField的大小(黑莓),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5901393/