1

我正在尝试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);
    }    
}
4

1 回答 1

1

我不是 100% 确定我理解你的问题,但我编辑了你的问题来描述我认为的问题。

当您的动画结束时,您会看到一个您不想要的空白屏幕。您必须按 Back/ESC 才能使白屏消失,这样您才能返回登录屏幕 ( NewScreen)。我假设您不想在第一次显示后看到初始动画屏幕(可能是因为它是加载启动屏幕)。

为此,您需要等到动画完成后再推动第二个屏幕。因此,删除此调用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);
      }
   }
于 2013-09-04T02:02:24.603 回答