我正在尝试MyScreen
在黑莓中创建一个具有主屏幕(下)动画的应用程序,它使图像从屏幕底部浮动到屏幕中间。然后在那之后,我想推另一个屏幕,它带来一个登录屏幕或其他东西(NewScreen
如下)。
动画后我得到一个空白屏幕。按下一次后,我得到了我从动画屏幕推送的屏幕。请指导我:我应该在哪里推动以获得完美的结果?
import net.rim.device.api.animation.AnimatedScalar;
import net.rim.device.api.animation.Animation;
import net.rim.device.api.animation.Animator;
import net.rim.device.api.animation.AnimatorListener;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.TransitionContext;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiEngineInstance;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.PopupScreen;
/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
public final class MyScreen extends MainScreen implements AnimatorListener {
private RectangleToMove _rect;
private Animator _animator;
private Animation _xanimation;
private Animation _yanimation;
private boolean _bAnimating;
public static final int BALL_WIDTH = 50;
public Bitmap splashimg;
static TransitionContext transitionContextIn;
static TransitionContext transitionContextOut;
static UiEngineInstance engine = Ui.getUiEngineInstance();
/**
* Creates a new MyScreen object
*/
public MyScreen() {
EncodedImage img = EncodedImage.getEncodedImageResource("logo.png");
splashimg = img.getBitmap();
_bAnimating = false;
int midScreen = (Display.getWidth() / 2) - img.getWidth()/2;
int endScreen = Display.getHeight();
_rect = new RectangleToMove(midScreen, BALL_WIDTH);
_animator = new Animator(30);
_animator.setAnimatorListener(this);
_yanimation = _animator.addAnimationFromTo(_rect.getY(),
AnimatedScalar.ANIMATION_PROPERTY_SCALAR, endScreen
- BALL_WIDTH, Display.getHeight() / 2-30,
Animation.EASINGCURVE_LINEAR, 3000L);
_yanimation.setRepeatCount(1f);
_yanimation.begin(0);
UiApplication.getUiApplication().pushScreen(new NewScreen());
}
protected void paint(Graphics g) {
if (_bAnimating) {
_rect.draw(g, splashimg);
}
}
public void animatorUpdate() {
invalidate();
doPaint();
}
public void animatorProcessing(boolean processing) {
_bAnimating = processing;
}
}
class RectangleToMove {
private int xPos;
private AnimatedScalar yPos;
public void draw(Graphics g, Bitmap splashimg) {
g.setBackgroundColor(Color.BLACK);
g.clear();
g.setColor(Color.SLATEGRAY);
g.drawBitmap(xPos, yPos.getInt(), splashimg.getWidth(),
splashimg.getHeight(), splashimg, 0, 0);
/*
* g.fillEllipse(xPos,yPos.getInt(),
* xPos+MyScreen.BALL_WIDTH,yPos.getInt(),xPos,
* yPos.getInt()+MyScreen.BALL_WIDTH,0,360);
*/
}
public int getX() {
return xPos;
}
public AnimatedScalar getY() {
return yPos;
}
RectangleToMove(int x, int y) {
xPos = x;
yPos = new AnimatedScalar(y);
}
}