下面的类是自定义标签字段,它绘制一个位图作为其背景。即时通讯重写的getprefferedwidth和获取首选高度,这会不会设置我的字段的高度和宽度?当前宽度和高度设置不正确
谢谢
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();
}发布于 2011-05-06 02:31:41
您还应该覆盖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());
}https://stackoverflow.com/questions/5901393
复制相似问题