Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 修改LabelField(blackberry)的大小_Java_Blackberry - Fatal编程技术网

Java 修改LabelField(blackberry)的大小

Java 修改LabelField(blackberry)的大小,java,blackberry,Java,Blackberry,类下面是自定义标签字段,它将位图绘制为其背景。Im覆盖GetPreferedWidth和getpreferredheight,这不会设置我的字段的高度和宽度吗?当前未正确设置宽度和高度 谢谢 public class TimerLabelField extends LabelField { private int colour; private Bitmap backgroundBitmap; public TimerLabelField(Obj

类下面是自定义标签字段,它将位图绘制为其背景。Im覆盖GetPreferedWidth和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();
    }

您还应该覆盖布局(整数宽度、整数高度):

protected void layout(int width, int height) {
    super.layout(width, height);
    setExtent(Math.min(width, this.BackgroundBitmap.getWidth()), Math.min(height, this.Backgroundbitmap.getHeight());
}