黑莓 - 方向改变后重新绘制我的标题栏
我正在编写一个使用自定义标题栏的黑莓应用程序。我的应用程序没有使用基于文本的标题栏,而是使用图像。
一旦设备(例如 BlackBerry Storm 或 Torch)的方向从纵向变为横向,我就无法重新绘制此标题栏。请参阅下面我的 titleBar 类的代码。
任何帮助将不胜感激!谢谢!!
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);
}
}
I am writing a BlackBerry application that uses a custom title bar. Rather than using the textual based title bar, my application uses an image.
I am having trouble redrawing this title bar once the orientation of the device, such as a BlackBerry Storm or Torch, changes from portrait to landscape. See my code for my titleBar Class below.
Any help would be appreciated! Thanks!!
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了!
这是因为我在构造函数中获取了宽度。当设备重新定向时,我将检索构造函数中保存的值。
这是固定代码:
Solved it!
It was because I was getting the width in the constructor. When the device was reoriented, I would retrieve the saved value which was taken in the constructor.
Here is the fixed code: