私のアプリにカスタムLabelFieldを実装しています。小さなフォントでうまくいきますが、フォントサイズを大きくすると正しく表示されません。ここであなたはこのイメージでそれを見ることができます。BlackberryのカスタムLabelFieldでテキストが正しく表示されない
あなたはそれがテキストの半分だけを示している画像で見ることができます。どのように私はこれを克服することができます。
ここでは、カスタムLabelFieldのコードを提供しています。私が間違っていることを教えてください。あなたは現在のデフォルトのフォントの高さにあなたのフィールドの高さを設定しているあなたのlayout
方法で
public class CustomLabelField extends Field
{
private String label;
private int fontSize;
private int foregroundColor;
private int backgroundColor;
public CustomLabelField(String label, int fontSize, int foregroundColor,
int backgroundColor,long style)
{
super(style);
this.label = label;
this.foregroundColor = foregroundColor;
this.backgroundColor = backgroundColor;
this.fontSize = fontSize;
}
protected void layout(int width, int height) {
setExtent(width, getFont().getHeight());
}
protected void paint(Graphics graphics) {
graphics.setBackgroundColor(backgroundColor);
graphics.clear();
graphics.setFont(setMyFont());
graphics.setColor(foregroundColor);
graphics.drawText(label, 0, 0, (int)(getStyle()& DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK),getWidth() - 6);
}
// Get font for the label field
public Font setMyFont()
{
try {
FontFamily alphaSansFamily = FontFamily.forName("BBAlpha Serif");
Font appFont = alphaSansFamily.getFont(Font.PLAIN, fontSize, Ui.UNITS_pt);
return appFont;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}