Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 黑莓-方向改变后重新绘制我的标题栏_User Interface_Blackberry_Blackberry Jde_Blackberry Storm_Blackberry Torch - Fatal编程技术网

User interface 黑莓-方向改变后重新绘制我的标题栏

User interface 黑莓-方向改变后重新绘制我的标题栏,user-interface,blackberry,blackberry-jde,blackberry-storm,blackberry-torch,User Interface,Blackberry,Blackberry Jde,Blackberry Storm,Blackberry Torch,我正在编写一个使用自定义标题栏的BlackBerry应用程序。我的应用程序使用的不是基于文本的标题栏,而是图像 当设备的方向(如黑莓风暴或火炬)从纵向变为横向时,我很难重新绘制此标题栏。请参阅下面标题栏类的代码 任何帮助都将不胜感激!谢谢 import net.rim.device.api.ui.container.MainScreen; import net.rim.device.api.ui.component.BitmapField; import net.rim.device.api.s

我正在编写一个使用自定义标题栏的BlackBerry应用程序。我的应用程序使用的不是基于文本的标题栏,而是图像

当设备的方向(如黑莓风暴或火炬)从纵向变为横向时,我很难重新绘制此标题栏。请参阅下面标题栏类的代码

任何帮助都将不胜感激!谢谢

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.main屏幕;
导入net.rim.device.api.ui.component.BitmapField;
导入net.rim.device.api.system.Bitmap;
导入net.rim.device.api.ui.Color;
导入net.rim.device.api.ui.Graphics;
导入net.rim.device.api.ui.*;
导入net.rim.device.api.ui.component.*;
导入net.rim.device.api.ui.container.*;
导入net.rim.device.api.system.*;
/**
*标题栏
*/
公共类标题栏扩展字段实现DrawStyle
{
私有整型字段宽度;
私人国际机场高度;
私人色彩;
私人背景色;
私有位图bgImage=Bitmap.getBitmapResource(“bgtTitle.png”);
私有位图标题图像=Bitmap.getBitmapResource(“logottitle.png”);
私有静态最终整型背景色=0x00000000;
公共标题栏()
{
超级(字段不可聚焦);
fieldHeight=titleImage.getHeight();
fieldWidth=Display.getWidth();
//背景颜色是黑色
背景颜色=背景颜色;
}
公共背景色(国际背景色)
{
背景色=_backgroundColor;
使无效();
}
受保护的空心布局(内部宽度、内部高度)
{
setExtent(getPreferredWidth(),getPreferredHeight());
}
public int getPreferredWidth()
{
返回场宽度;
}
public int getPreferredHeight()
{
返回场高度;
}
受保护的空心漆(图形)
{
int w=this.getPreferredWidth();
int h=this.getPreferredHeight();
int width_of_bg=10;
int paint_position=0;
int screen_width=Display.getWidth();
而(油漆位置解决了它

这是因为我在构造函数中获取宽度。当设备重新定向时,我将检索构造函数中获取的保存值

以下是固定代码:

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);
    }
}
import net.rim.device.api.ui.container.main屏幕;
导入net.rim.device.api.ui.component.BitmapField;
导入net.rim.device.api.system.Bitmap;
导入net.rim.device.api.ui.Color;
导入net.rim.device.api.ui.Graphics;
导入net.rim.device.api.ui.*;
导入net.rim.device.api.ui.component.*;
导入net.rim.device.api.ui.container.*;
导入net.rim.device.api.system.*;
/**
*标题栏
*/
公共类标题栏扩展字段实现DrawStyle
{
私有整型字段宽度;
私人国际机场高度;
私人色彩;
私人背景色;
私有位图bgImage=Bitmap.getBitmapResource(“bgtTitle.png”);
私有位图标题图像=Bitmap.getBitmapResource(“logottitle.png”);
私有静态最终整型背景色=0x00000000;
公共标题栏()
{
超级(字段不可聚焦);
fieldHeight=titleImage.getHeight();
fieldWidth=Display.getWidth();
//背景颜色是黑色
背景颜色=背景颜色;
}
公共背景色(国际背景色)
{
背景色=_backgroundColor;
使无效();
}
受保护的空心布局(内部宽度、内部高度)
{
setExtent(getPreferredWidth(),getPreferredHeight());
}
public int getPreferredWidth()
{
返回Display.getWidth();
}
public int getPreferredHeight()
{
返回场高度;
}
受保护的空心漆(图形)
{
int w=this.getPreferredWidth();
int h=this.getPreferredHeight();
int width_of_bg=10;
int paint_position=0;

while(paint_position)你有什么问题?你能提供一个屏幕截图,或者更详细地说明绘图问题是什么吗?基本上,当应用程序启动时,标题看起来很好,居中,背景图像重复。但是,如果设备旋转,屏幕重新调整(如暴风雪/火炬),则上面的代码不会“重画”标题,也不会居中。我希望在设备切换方向后,它会“重画”。