문제

사용자 정의 제목 표시 줄을 사용하는 BlackBerry 응용 프로그램을 작성하고 있습니다.텍스트 기반 제목 표시 줄을 사용하는 것이 아니라 내 응용 프로그램은 이미지를 사용합니다.

BlackBerry Storm 또는 Torch와 같은 장치의 방향이되면이 제목 표시 줄을 다시 그리는 데 어려움이 있습니다.아래의 제 타이틀 바 클래스의 코드를 참조하십시오.

도움이 될 것입니다!고마워 !!

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

/**
 * Title Bar
 */

public class TitleBar extends Field implements DrawStyle
{
    private int fieldWidth;
    private int fieldHeight;
    private int fontColour;
    private int backgroundColor;

    private Bitmap bgImage = Bitmap.getBitmapResource("bgtitle.png");
    private Bitmap titleImage =  Bitmap.getBitmapResource("logotitle.png");
    private static final int BACKGROUND_COLOR = 0x00000000;


    public TitleBar() 
    {
        super(Field.NON_FOCUSABLE);
        fieldHeight = titleImage.getHeight();
        fieldWidth = Display.getWidth();

        //background color is black
        backgroundColor = BACKGROUND_COLOR;        
    }

    public void setBackgroundColour(int _backgroundColour)
    {
        backgroundColor = _backgroundColour;
        invalidate();
    }

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

    public int getPreferredWidth() 
    {
        return fieldWidth;
    }

    public int getPreferredHeight() 
    {
        return fieldHeight;
    }

    protected void paint(Graphics graphics) 
    {

        int w = this.getPreferredWidth();
        int h = this.getPreferredHeight();

        int width_of_bg = 10;
        int paint_position = 0;

        int screen_width = Display.getWidth();
        while(paint_position<screen_width){
            graphics.drawBitmap(paint_position, 0, w, h, bgImage, 0, 0);
            paint_position += width_of_bg;
        }

        int marginX = (w- titleImage.getWidth() ) / 2 ; 
        graphics.drawBitmap(marginX, 0, w, h, titleImage, 0, 0);
    }
}
.

도움이 되었습니까?

해결책

해결되었습니다!

생성자의 너비를 얻고 있기 때문입니다.장치가 재조정되면 생성자에서 가져온 저장된 값을 검색합니다.

여기에 고정 코드가 있습니다 :

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

/**
 * Title Bar
 */

public class TitleBar extends Field implements DrawStyle
{
    private int fieldWidth;
    private int fieldHeight;
    private int fontColour;
    private int backgroundColor;

    private Bitmap bgImage = Bitmap.getBitmapResource("bgtitle.png");
    private Bitmap titleImage =  Bitmap.getBitmapResource("logotitle.png");
    private static final int BACKGROUND_COLOR = 0x00000000;


    public TitleBar() 
    {
        super(Field.NON_FOCUSABLE);
        fieldHeight = titleImage.getHeight();
        fieldWidth = Display.getWidth();

        //background color is black
        backgroundColor = BACKGROUND_COLOR;        
    }

    public void setBackgroundColour(int _backgroundColour)
    {
        backgroundColor = _backgroundColour;
        invalidate();
    }

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

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

    public int getPreferredHeight() 
    {
        return fieldHeight;
    }

    protected void paint(Graphics graphics) 
    {

        int w = this.getPreferredWidth();
        int h = this.getPreferredHeight();

        int width_of_bg = 10;
        int paint_position = 0;

        while(paint_position<w){
            graphics.drawBitmap(paint_position, 0, w, h, bgImage, 0, 0);
            paint_position += width_of_bg;
        }

        int marginX = (w- titleImage.getWidth() ) / 2 ; 
        graphics.drawBitmap(marginX, 0, w, h, titleImage, 0, 0);
    }
}
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top