Blackberry 我如何在黑莓手机上设置背景图像?
我想在垂直场管理器中设置背景图像。我试过了,但它没有填满高度,你可以在我的屏幕上看到。下面是我的代码,我做错了什么,请帮助我Blackberry 我如何在黑莓手机上设置背景图像?,blackberry,Blackberry,我想在垂直场管理器中设置背景图像。我试过了,但它没有填满高度,你可以在我的屏幕上看到。下面是我的代码,我做错了什么,请帮助我 vfmCenter = new VerticalFieldManager(FIELD_HCENTER) { public void paint(Graphics graphics) { graphics.clear(); graphics.drawBitmap(0, 0,dev
vfmCenter = new VerticalFieldManager(FIELD_HCENTER)
{
public void paint(Graphics graphics)
{
graphics.clear();
graphics.drawBitmap(0, 0,deviceWidth,deviceHeight,newimg,0,0);
super.paint(graphics);
}
protected void sublayout( int maxWidth, int maxHeight)
{
int width = Display.getWidth();
int height = Display.getHeight();
super.sublayout( width, height);
setExtent( width, height);
}
};
vfmMain.add(vfmCenter);
this.add(vfmMain);
试着这样做:
VerticalFieldManager vertical=new VerticalFieldManager()
{
protected void paint(Graphics g)
{
g.drawBitmap(0, 0,Display.getWidth(), Display.getHeight(), bitmap, 0, 0);
super.paint(g);
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
add(vertical);
您可以获得。这是使用getMainManager的简单方法,但整个背景不是特定的字段管理器
getMainManager().setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("sample.png")));
我之前也面临同样的问题。。我用这个解决了我的问题
class MyClass extends MainScreen
{
// function for scaling your image to fit the screen
public EncodedImage scaleImage(EncodedImage source, int requiredWidth, int requiredHeight)
{
int currentWidthFixed32 = Fixed32.toFP(source.getWidth());
int requiredWidthFixed32 = Fixed32.toFP(requiredWidth);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
int currentHeightFixed32 = Fixed32.toFP(source.getHeight());
int requiredHeightFixed32 = Fixed32.toFP(requiredHeight);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
return source.scaleImage32(scaleXFixed32, scaleYFixed32);
}
public MyClass
{
ei = EncodedImage.getEncodedImageResource("res/background_image");
ei1= scaleImage(ei,requires_width,required_height);
vfm= new VerticalFieldManager(VerticalFieldManager.USE_ALL_HEIGHT|VerticalFieldManager.USE_ALL_WIDTH);
vfm.setBackground(BackgroundFactory.createBitmapBackground(ei1.getBitmap()));
vfm.add(new LabelField("hello notice the background behind me");
add(vfm);
}
}
试试这个。我想它会对你有用的 仅绘制位图不会增加或减少图像的大小。。这是verticalfieldmanager中的问题