2010-03-09 108 views
1

我想在背景图像上设置一个图像的位置。该位置可以在屏幕上的任何位置。背景图像黑莓图像

我可以有一个示例代码或链接或教程吗?

回答

2

这里是我如何做到这一点:

这个工作在4.6.0后来因为BackgroundFactory

// Create the background image and the image field to put on top 
Background bg = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource(bgImgPath); 
Bitmap bmp = Bitmap.getBitmapResource(imgPath); 
BitmapField imgField = new BitmapField(bmp); 
// Create the field manager 
VerticalFieldManager manager = new VerticalFieldManager() 
{ 
    // Overide the sublayout of the field manager to set the position of 
    // the image directly 
    protected void sublayout(int width, int height) 
    { 
    setPositionChild(imgField, positionX, positionY) 
    setExtent(width, height) 
    } 
}; 
// Set the background of the field manager 
manager.setBackground(bg); 
// add the bitmap field to the field manager 
manager.add(imgField); 
// add the field manager to the screen 
add(manager); 

对于多个图像,你可以做一个布局管理器类,并使用该位置所有的图片,其中你希望他们使用类似的技术。有一个用于制作和使用布局管理器的教程,我会尝试将其挖掘并将其发布回来。

如果您使用4.5.0或更早的版本,我使用布局管理器,只需像添加其他图像一样添加背景图片,但首先添加背景图片以便底部绘制。

就像我说的,我会尝试找到布局管理器的教程。

+0

感谢很多示例代码。 m等待教程,因为我正在开发应用程序在4.5.0版本 – Master 2010-03-10 13:00:01

+1

这里是一个:http://docs.blackberry.com/en/developers/deliverables/1180/development.pdf#24 这是在第24页的pdf。 整个手册是从4.5.0,所以它应该都适合你。 – 2010-03-10 14:56:17

1

您可以创建扩展Manager类 在这里,您可以指定背景图片,以及你可以在一个位置定位等图像类,你要

class Test extends MainScreen 
{ 
    Test() 
    { 
     super(); 
     Bitmap bmp = Bitmap.getBitmapResource("image1.png"); 
     BitmapField bmpf = new BitmapField(bmp); 
     Mymanager obj = new Mymanager(); 
     obj.add(bmpf); 
    } 
} 

class Mymanager extends Manager 
{ 
final Bitmap background = Bitmap.getBitmapResource("back.png"); 
    protected void paint(Graphics g) 
    { 
    g.drawrect(0,0,background.getWidth,background.getheight,background,0,0); 
    } 
    protected void sublayout(int width, int height) 
    { 
    Field field = getfield(0); 
    layoutchild(field,100,100); 
    setPositionchild(field,20,10); 

    setExtent(Display.getWidth,Display.getHeight); 
    } 
}