2010-06-12 7 views
0

J'ai créé un bouton personnalisé et je place le tas de boutons personnalisés dans un champ verticalfieldManager, j'ai aligné le verticalField Manager au centre. quand je crée un bouton buttonField par défaut, alors verticalfield Manager est capable d'aligner le bouton au centre. mais quand j'affecte custombuttonfield dans le gestionnaire verticalField, il ne s'aligne pas au centre.Champ CustomButton ne s'alignant pas au centre

ici est mon custombuttoncode

public CustomButtonField(String label,long style) { 
    super(style); 
    this.label = label; 
    onPicture = Bitmap.getBitmapResource(onPicturePath); 
    font = getFont(); 
    this.setPadding(5,5, 5, 5); 
} 

public String getLabel() { 
    return label; 
} 

public int getPreferredHeight() { 
    return onPicture.getHeight(); 
} 

public int getPreferredWidth() { 
    return onPicture.getWidth(); 
} 

protected void layout(int width , int height) { 
    setExtent(Math.min(width, Display.getWidth()), Math.min(height,getPreferredHeight())); 
} 

protected void paint(Graphics graphics) { 
    int texty =(getHeight()-getFont().getHeight())/2; 

    if (isFocus()) { 
     graphics.setColor(Color.BLACK); 
     graphics.drawBitmap(0, 0, getWidth(), getHeight(),onPicture , 0, 0); 
     graphics.setColor(Color.WHITE); 
     graphics.setFont(font); 
     graphics.drawText(label,0,texty,DrawStyle.ELLIPSIS,getWidth()); 
    } else { 
     graphics.drawBitmap(0, 0, getWidth(), getHeight(),onPicture , 0, 0); 
     graphics.setColor(Color.WHITE); 
     graphics.setFont(font); 
     graphics.drawText(label,0,texty,DrawStyle.ELLIPSIS,getWidth()); 
    } 
} 

public boolean isFocusable() { 
    return true; 
} 

protected void onFocus(int direction) { 
    super.onFocus(direction); 
    invalidate(); 
} 

protected void onUnfocus() { 
    super.onUnfocus(); 
    invalidate(); 
} 

protected boolean navigationClick(int status, int time) { 
    fieldChangeNotify(0); 
    return true; 
} 

protected boolean keyChar(char character, int status, int time) { 
    if (character == Keypad.KEY_ENTER) { 
     fieldChangeNotify(0); 
     return true; 
    } 
    return super.keyChar(character, status, time); 
} 

}

Répondre

2

Lorsque vous créez le bouton que vous devez passer le drapeau Field.FIELD_HCENTER comme l'un de vos drapeaux de style.

CustomButtonField button = new CustomButtonField("TestLabel", Field.FIELD_HCENTER); 
Questions connexes