BlackBerry - ButtonField with centered Bitmap

后端 未结 1 2020
滥情空心
滥情空心 2021-01-16 18:46

I have a class that extends from ButtonField :

class BitmapButtonField extends ButtonField
{
    private Bitmap _bitmap;
    private int _buttonWidth;
    pr         


        
相关标签:
1条回答
  • 2021-01-16 19:18

    In paint() to define x offset for image there is a code:

    int x = (getPreferredWidth() - _bitmap.getWidth()) >> 1;
    

    It is ok, still button can have other size, because of:

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

    Try to use

    protected void layout(int width, int height) 
    {
        setExtent(getPreferredWidth(), getPreferredHeight());
    }
    
    0 讨论(0)
提交回复
热议问题