我想在垂直字段管理器中设置背景图像。我试过了,但高度不够,您可以在屏幕上看到它。并在我的代码中跟随我在做什么错误,请帮助我。

 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);

最佳答案

我之前也遇到过同样的问题。

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);
   }
}

尝试这个。我认为它将为您服务!

10-04 16:56