黑莓 - 背景图片/动画RIM OS 4.5.0 [英] Blackberry - background image/animation RIM OS 4.5.0

查看:248
本文介绍了黑莓 - 背景图片/动画RIM OS 4.5.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮帮我,如何设置的背景图像屏幕以及如何做动画在任何场或文字?

Please help me, how to set a background image for screen and How to do animations on any-field or on text?

感谢您....

推荐答案

在Screen类有一个<一个href=\"http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/ui/Screen.html#paintBackground%28net.rim.device.api.ui.Graphics%29\">protected无效paintBackground(图形图像)方法。

由于某种原因,我们不能用它直接在屏幕上绘制背景图片。美中不足的是:paintBackground方法是从Field类派​​生,我们可以在VerticalFieldManager使用它的例子:

Background image

In Screen class there is a protected void paintBackground(Graphics graphics) method.
By some reason we can't use it directly to paint background image in screen. The catch: paintBackground method is derived from Field class, and we can use it in VerticalFieldManager on example:

class BgScreen extends MainScreen implements FieldChangeListener {
 ButtonField mButton;
 public BgScreen(Bitmap background) {
  super();
  BGVerticalFieldManager manager = 
   new BGVerticalFieldManager(background);
  add(manager);
  mButton = new ButtonField("Button", ButtonField.CONSUME_CLICK);
  mButton.setChangeListener(this);
  manager.add(mButton);
 }

 public void fieldChanged(Field field, int context) {
  if (mButton == field)
   Dialog.inform("You pressed button");
 }
}

class BGVerticalFieldManager extends VerticalFieldManager {
 Bitmap mBgBitmap = null;
 int mBgWidth = -1;
 int mBgHeight = -1;
 int mBgX = -1;
 int mBgY = -1;

 public BGVerticalFieldManager(Bitmap background) {
  super(USE_ALL_WIDTH | USE_ALL_HEIGHT);
  mBgBitmap = background;
  mBgWidth = mBgBitmap.getWidth();
  mBgHeight = mBgBitmap.getHeight();
  mBgX = (Display.getWidth() - mBgWidth) >> 1;
  mBgY = (Display.getHeight() - mBgHeight) >> 1;

 }

 protected void paintBackground(Graphics graphics) {
  paintBackgroundBitmap(graphics);
  super.paintBackground(graphics);
 }

 private void paintBackgroundBitmap(Graphics graphics) {
  if (null != mBgBitmap) {
   graphics.drawBitmap(
    mBgX, mBgY, mBgWidth, mBgHeight, mBgBitmap, 0, 0);
  }
 }
}

GIF动画

要使用GIF动画,覆盖<一个href=\"http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/ui/Screen.html#paint%28net.rim.device.api.ui.Graphics%29\">protected无效漆(图形图像)的方法和使用<一个href=\"http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/ui/Graphics.html#drawImage%28int,%20int,%20int,%20int,%20net.rim.device.api.system.En$c$cdImage,%20int,%20int,%20int%29\">drawImage增加的帧索引。使用<一个href=\"http://www.blackberry.com/developers/docs/4.5.0api/java/util/Timer.html#scheduleAtFixedRate%28java.util.TimerTask,%20long,%20long%29\">Timer.scheduleAtFixedRate无效域:

GIF animation

To use GIF animation, override protected void paint(Graphics graphics) method and use drawImage of incremented frame index. Use Timer.scheduleAtFixedRate to invalidate field:

class GIFVerticalFieldManager extends VerticalFieldManager {
    EncodedImage mGIFImage = null;
    int mGIFWidth = -1;
    int mGIFHeight = -1;
    int mGIFX = -1;
    int mGIFY = -1;
    int mGIFFrameCount = -1;
    int mGIFFrameIndex = -1;
    final int mGIFDelay = 30;

    public GIFVerticalFieldManager(EncodedImage gifAnimation) {
    	super(USE_ALL_WIDTH | USE_ALL_HEIGHT);
    	mGIFImage = gifAnimation;
    	mGIFWidth = mGIFImage.getWidth();
    	mGIFHeight = mGIFImage.getHeight();
    	mGIFX = (Display.getWidth() - mGIFWidth) >> 1;
    	mGIFY = (Display.getHeight() - mGIFHeight) >> 1;
    	mGIFFrameCount = mGIFImage.getFrameCount();
    	mGIFFrameIndex = 0;

    	Timer timer = new Timer();
    	timer.scheduleAtFixedRate(new TimerTask() {
    		public void run() {
    			invalidate();
    		}
    	}, mGIFDelay, mGIFDelay);
    }

    protected void paint(Graphics graphics) {
    	paintGifAnimation(graphics);
    	super.paint(graphics);
    }

    private void paintGifAnimation(Graphics graphics) {
    	if (null != mGIFImage) {
    		graphics.drawImage(
    			mGIFX, mGIFY, mGIFWidth, mGIFHeight, 
			mGIFImage, mGIFFrameIndex, 0, 0);
    		mGIFFrameIndex++;
    		if (mGIFFrameIndex > mGIFFrameCount - 1)
    			mGIFFrameIndex = 0;
    	}
    }
}

编辑:大文章 - <一个href=\"http://na.blackberry.com/eng/devjournals/resources/journals/jan%5F2006/direct%5Fscreen%5Fdrawing.jsp\">Direct屏幕绘图

这篇关于黑莓 - 背景图片/动画RIM OS 4.5.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆