垂直屏幕分割转换(动画)屏幕、动画

由网友(微笑,向前行)分享简介:动画应该做到以下几点:The animation should do the following:垂直分割屏幕分为两部分。 在上部向上移动。下部向下移动。最后,在逆向。 (关闭屏幕)Vertically split the screen into 2 parts. Upper part moving upwa...

动画应该做到以下几点:

The animation should do the following:

垂直分割屏幕分为两部分。 在上部向上移动。 下部向下移动。 最后,在逆向。 (关闭屏幕) Vertically split the screen into 2 parts. Upper part moving upward. Lower part moving down. Finally, the reverse way. (closing the screen)

推荐答案

我们的想法很简单:

在保存的活动为您作为一个位图 在分割位分为两部分 动画位图向外(向上或向下)

为了获得活动的位图:

View root = currActivity.getWindow().getDecorView().findViewById(android.R.id.content);
root.setDrawingCacheEnabled(true);
Bitmap bmp = root.getDrawingCache();

为了分割位图:

int splitYCoord = (splitYCoord != -1 ? splitYCoord : bmp.getHeight() / 2);
if (splitYCoord > bmp.getHeight())
            throw new IllegalArgumentException("Split Y coordinate [" + splitYCoord + "] exceeds the activity's height [" + bmp.getHeight() + "]");
Bitmap mBmp1 = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), splitYCoord);
Bitmap mBmp2 = Bitmap.createBitmap(bmp, 0, splitYCoord, bmp.getWidth(), bmp.getHeight() - splitYCoord);
private static int[] mLoc1;
private static int[] mLoc2;
mLoc1 = new int[]{0, root.getTop()};
mLoc2 = new int[]{0, root.getTop() + splitYCoord};
private static ImageView mTopImage;
private static ImageView mBottomImage;
mTopImage = createImageView(destActivity, mBmp1, mLoc1);
mBottomImage = createImageView(destActivity, mBmp2, mLoc2);

private static ImageView createImageView(Activity destActivity, Bitmap bmp, int loc[]) {
    ImageView imageView = new ImageView(destActivity);
    imageView.setImageBitmap(bmp);

    WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();
    windowParams.gravity = Gravity.TOP;
    windowParams.x = loc[0];
    windowParams.y = loc[1];
    windowParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    windowParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
    windowParams.flags =
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
    windowParams.format = PixelFormat.TRANSLUCENT;
    windowParams.windowAnimations = 0;
    destActivity.getWindowManager().addView(imageView, windowParams);

    return imageView;
}

在我们创建的位图,动画应用

After we created the bitmaps, Apply Animation

AnimatorSet mSetAnim = new AnimatorSet();
mTopImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
mBottomImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
mSetAnim.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        clean(destActivity);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        clean(destActivity);
                    }
                        ...
                });

Animator anim1 = ObjectAnimator.ofFloat(mTopImage, "translationY", mTopImage.getHeight() * -1);
Animator anim2 = ObjectAnimator.ofFloat(mBottomImage, "translationY", mBottomImage.getHeight());

mSetAnim.setDuration(duration);
mSetAnim.playTogether(anim1, anim2);
mSetAnim.start();

private void clean(Activity activity) {
    if (mTopImage != null) {
        mTopImage.setLayerType(View.LAYER_TYPE_NONE, null);
        try {
            activity.getWindowManager().removeViewImmediate(mBottomImage);
        } catch (Exception ignored) {}
    }
    if (mBottomImage != null) {
        mBottomImage.setLayerType(View.LAYER_TYPE_NONE, null);
        try {
            activity.getWindowManager().removeViewImmediate(mTopImage);
        } catch (Exception ignored) {}
    }

    mBmp1 = null;
    mBmp2 = null;
}

以上code只供参考之用。你可以找到完整的演示从下面的链接。

Above code is just for reference purpose. You can find full demo from below link.

参考链接: ActivitySplitAnimation

阅读全文

相关推荐

最新文章