Android Daydream没有正确阅读轮播

时间:2014-07-27 05:53:06

标签: android daydream

我有一个动画,在做梦的同时滚动一个ImageView图层,我希望它在屏幕的薄边滚动(即在720x上的1280 x 720屏幕上)我得到一个显示变量,告诉我显示是否在景观轮换。有时这并没有使它做出正确的反应,它会在错误的轴上滚动。我试过很多方面解决这个问题。包括拉动ImageView所在框架的尺寸。这仍然随机错误的宽度和高度。它几乎感觉就像屏幕布局正确,轴位置交换(横向x仍然是最短边,y是最长的)这是随机发生的,我无法弄清楚原因。

private void initializeAlbumArtScroll() {

    albumArtwork.setX(0);
    albumArtwork.setY(0);

    mAnimator = albumArtwork.animate().x(0)
            .y(0)
            .setDuration(1)
            .setStartDelay(0)
            .setInterpolator(sInterpolator)
            .withEndAction(new Runnable() {
                @Override
                public void run() {
                    if (inPortrait) {
                        Log.i(TAG, "Scroll Portrait");
                        startAlbumArtLeftScroll();
                    } else {
                        Log.i(TAG, "Scroll Landscape");
                        startAlbumArtUpScroll();
                    }
                }
            });

    // Start the animation
    mAnimator.start();
}

/**
 * Album art scroll from the right of the screen to the left
 */
private void startAlbumArtLeftScroll() {
    albumArtwork.setX(0);
    albumArtwork.setY(0);

    mAnimator = albumArtwork.animate().x(-albumArtwork.getWidth() + screenWidth)
            .y(0)
            .setDuration(animationDuration)
            .setStartDelay(500)
            .setInterpolator(sInterpolator)
            .withEndAction(new Runnable() {
                @Override
                public void run() {
                    startAlbumArtRightScroll();
                }
            });

    // Start the animation
    mAnimator.start();
}

daydreamFrame.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    if ((display.getRotation() == Surface.ROTATION_0 || display.getRotation() == Surface.ROTATION_180) && !inPortrait) {
                        Log.i(TAG, "Now in portrait");
                        if (mAnimator != null) {
                            mAnimator.cancel();
                        }
                        inPortrait = true;
                        initializeAlbumArtScroll();
                    } else if ((display.getRotation() == Surface.ROTATION_270 || display.getRotation() == Surface.ROTATION_90) && inPortrait) {
                        Log.i(TAG, "Now in landscape");
                        if (mAnimator != null) {
                            mAnimator.cancel();
                        }
                        inPortrait = false;
                        initializeAlbumArtScroll();
                    }
                }
            });

0 个答案:

没有答案