我正在尝试创建一个在Blackberry中具有主屏幕(下面为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);
}
}
答案 0 :(得分:1)
我并非100%确定我理解您的问题,但我编辑了您的问题以描述我认为的问题。
当动画结束时,您会看到一个您不想要的空白屏幕。您必须按Back / ESC才能使白屏消失,以便您可以返回登录屏幕(NewScreen
)。我假设您不希望在第一次显示之后看到初始动画屏幕(可能是因为它是加载或 splash 屏幕)。
要执行此操作,您需要等到动画完成,然后再按第二个屏幕。因此,删除此次调用pushScreen
:
UiApplication.getUiApplication().pushScreen(new NewScreen());
你在MyScreen
构造函数中有。此时,动画尚未完成,因此推送NewScreen
。
然后,在AnimatorListener
被告知动画停止时按下屏幕。如果您不希望动画屏幕可见,则在通过屏幕进行备份时,请在按下第二个屏幕后弹出:
public void animatorProcessing(boolean processing) {
_bAnimating = processing;
if (!processing) {
// the animation is complete
UiApplication.getUiApplication().pushScreen(new NewScreen());
// use this line if the instance of `MyScreen` should not be
// visible after the user presses Back/ESC:
UiApplication.getUiApplication().popScreen(this);
}
}