我在打開我的應用程序時在位圖字段中添加了啓動屏幕圖像。在線程方法中,我從httpconnection獲取徽標。在黑莓的上方位圖字段中加載gif圖像
完成線程執行後,我刪除了位圖字段。並在該屏幕上加載徽標。
我想在執行線程時顯示在位圖字段上方加載gif圖像。
請幫忙。
嗨,我已經使用位圖字段在全屏顯示圖像。在上面的位圖字段中如何顯示加載gif圖像。那是我的問題。
我在打開我的應用程序時在位圖字段中添加了啓動屏幕圖像。在線程方法中,我從httpconnection獲取徽標。在黑莓的上方位圖字段中加載gif圖像
完成線程執行後,我刪除了位圖字段。並在該屏幕上加載徽標。
我想在執行線程時顯示在位圖字段上方加載gif圖像。
請幫忙。
嗨,我已經使用位圖字段在全屏顯示圖像。在上面的位圖字段中如何顯示加載gif圖像。那是我的問題。
轉到此鏈接:
您將得到AnimatedGIFField.java文件。用專名保存它。寫這樣的....
GIFEncodedImage bitmapImage=(GIFEncodedImage)GIFEncodedImage.getEncodedImageResource("loading.gif");
AnimatedGIFField image_field=new AnimatedGIFField(bitmapImage);
add(image_field);
注:如果在> 6.0版本中使用這種 「loading.gif」 它給exceptoin。爲此,您必須將該文件重命名爲「loading.agif」。意味着你必須使用的7.0版本「loading.agif」不是「loading.gif」。重命名文件,並把在res文件夾和更改文件名:
GIFEncodedImage.getEncodedImageResource(「loading.agif」)
如果您有任何疑問都在計算器上的聊天室名稱「生活黑莓」澄清你和我們的疑惑。
嗨,我已經使用位圖字段全屏顯示圖像。在上面的位圖字段中如何顯示加載gif圖像。那是我的問題。 – RVG
使用下面的類到GIF
文件加載到BitmapField
, 要調用它,並顯示它使用下面的代碼:
GIFEncodedImage yourImage =(GIFEncodedImage)GIFEncodedImage.getEncodedImageResource("picture.gif");
AnimatedGIFField yourImageField =new AnimatedGIFField(yourImage);
add(yourImageField);
**
**
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.system.GIFEncodedImage;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.Color;
//A field that displays an animated GIF.
public class AnimatedGIFField extends BitmapField
{
private GIFEncodedImage _image; //The image to draw.
private int _currentFrame; //The current frame in the animation sequence.
private int _width; //The width of the image (background frame).
private int _height; //The height of the image (background frame).
private AnimatorThread _animatorThread;
public AnimatedGIFField(GIFEncodedImage image)
{
this(image, 0);
}
public AnimatedGIFField(GIFEncodedImage image, long style)
{
//Call super to setup the field with the specified style.
//The image is passed in as well for the field to configure its required size.
super(image.getBitmap(), style);
//Store the image and it's dimensions.
_image = image;
_width = image.getWidth();
_height = image.getHeight();
//Start the animation thread.
_animatorThread = new AnimatorThread(this);
_animatorThread.start();
}
protected void paint(Graphics graphics)
{
//Call super.paint. This will draw the first background frame and handle any required focus drawing.
super.paint(graphics);
//Don't redraw the background if this is the first frame.
if (_currentFrame != 0)
{
//Draw the animation frame.
graphics.drawImage(_image.getFrameLeft(_currentFrame), _image.getFrameTop(_currentFrame),
_image.getFrameWidth(_currentFrame), _image.getFrameHeight(_currentFrame), _image, _currentFrame, 0, 0);
}
}
//Stop the animation thread when the screen the field is on is
//popped off of the display stack.
protected void onUndisplay()
{
_animatorThread.stop();
super.onUndisplay();
}
//A thread to handle the animation.
private class AnimatorThread extends Thread
{
private AnimatedGIFField _theField;
private boolean _keepGoing = true;
private int _totalFrames; //The total number of frames in the image.
private int _loopCount; //The number of times the animation has looped (completed).
private int _totalLoops; //The number of times the animation should loop (set in the image).
public AnimatorThread(AnimatedGIFField theField)
{
_theField = theField;
_totalFrames = _image.getFrameCount();
_totalLoops = _image.getIterations();
}
public synchronized void stop()
{
_keepGoing = false;
}
public void run()
{
while(_keepGoing)
{
//Invalidate the field so that it is redrawn.
UiApplication.getUiApplication().invokeAndWait(new Runnable()
{
public void run()
{
_theField.invalidate();
}
});
try
{
//Sleep for the current frame delay before the next frame is drawn.
sleep(_image.getFrameDelay(_currentFrame) * 10);
}
catch (InterruptedException iex)
{} //Couldn't sleep.
//Increment the frame.
++_currentFrame;
if (_currentFrame == _totalFrames)
{
//Reset back to frame 0 if we have reached the end.
_currentFrame = 0;
++_loopCount;
//Check if the animation should continue.
if (_loopCount == _totalLoops)
{
_keepGoing = false;
}
}
}
}
}
}
您將該位圖字段添加到VerticalFieldManager (在paint方法graphics.setBitmap();)背景中並編寫下面的代碼; – alishaik786