2012-01-20 3 views
3

私は、垂直フィールドマネージャで背景画像を設定したいと思います。私は試してみましたが、それは私の画面でそれを見ることができる高さで満たされていません。私のコードで、私が間違ってやっていることは私を助けてください。ブラックベリーでBackgroungdイメージを設定する方法は?

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

enter image description here

+0

ビットマップを描画するだけでイメージのサイズが増減しません。これはverticalfieldmanagerの問題です – Swati

答えて

2
私も以前同じ問題に直面していた

を使用して簡単です..私はこれで私の問題を解決しました。..

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

これを試して。私はそれがあなたのために働くと思います!

+0

Thanx for Replay .. – Hasmukh

+0

あなたのコードで問題が解決しました。 – Hasmukh

+0

いつも歓迎!! – Swati

0

このようにしてみてください。

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

あなたが得ることができます。

0

これはgetMainManagerが、全体の背景ではない特定のフィールドマネージャー

getMainManager().setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("sample.png"))); 
関連する問題