首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >修改LabelField (黑莓)的大小

修改LabelField (黑莓)的大小
EN

Stack Overflow用户
提问于 2011-05-06 00:51:50
回答 1查看 705关注 0票数 1

下面的类是自定义标签字段,它绘制一个位图作为其背景。即时通讯重写的getprefferedwidth和获取首选高度,这会不会设置我的字段的高度和宽度?当前宽度和高度设置不正确

谢谢

代码语言:javascript
复制
   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();
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-06 02:31:41

您还应该覆盖layout(int width, int height)

代码语言:javascript
复制
protected void layout(int width, int height) {
    super.layout(width, height);
    setExtent(Math.min(width, this.BackgroundBitmap.getWidth()), Math.min(height, this.Backgroundbitmap.getHeight());
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5901393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档