activity或者view之间调整加个动画

解决方案 »

  1.   

    你这不是自己写的吧,motion event在move的时候,你移动下所在页试试,你这应该是up的时候才开始动画
      

  2.   

    贴一下我的代码吧:@Override
        protected void dispatchDraw(Canvas canvas) {
            boolean restore = false;
            // ADW: If using old wallpaper rendering method...
            if (!lwpSupport && mWallpaperDrawable != null) {
                float x = getScrollX() * mWallpaperOffset;
                if (x + mWallpaperWidth < getRight() - getLeft()) {
                    x = getRight() - getLeft() - mWallpaperWidth;
                }
                // ADW: added tweaks for when scrolling "beyond bounce limits" :P
                if (getScrollX() < 0)
                    x = getScrollX();
                if (getScrollX() > getChildAt(getChildCount() - 1).getRight()
                        - (getRight() - getLeft())) {
                    x = (getScrollX() - mWallpaperWidth + (getRight() - getLeft()));
                }
                // ADW lets center the wallpaper when there's only one screen...
                if (!mWallpaperScroll || getChildCount() == 1)
                    x = (getScrollX() - (mWallpaperWidth / 2) + (getRight() / 2));
                final int y = mWallpaperY;
                canvas.drawBitmap(mWallpaperDrawable.getBitmap(), x, y, mPaint);
            }
            if (!mSensemode) {
                // If the all apps drawer is open and the drawing region for the
                // workspace
                // is contained within the drawer's bounds, we skip the drawing.
                // This requires
                // the drawer to be fully opaque.
                if ((mLauncher.isAllAppsVisible()) || mLauncher.isEditMode()) {
                    return;
                }
                // ViewGroup.dispatchDraw() supports many features we don't need:
                // clip to padding, layout animation, animation listener,
                // disappearing
                // children, etc. The following implementation attempts to
                // fast-track
                // the drawing dispatch by drawing only what we know needs to be
                // drawn.            boolean fastDraw = mTouchState != TOUCH_STATE_SCROLLING
                        && mNextScreen == INVALID_SCREEN;
                // If we are not scrolling or flinging, draw only the current screen
                if (fastDraw) {
                    drawChild(canvas, getChildAt(mCurrentScreen), getDrawingTime());
                } else {
                    final long drawingTime = getDrawingTime();
                    // If we are flinging, draw only the current screen and the
                    // target screen
                    if (mNextScreen >= 0 && mNextScreen < getChildCount() &&
                            Math.abs(mCurrentScreen - mNextScreen) == 1) {
                        drawChild(canvas, getChildAt(mCurrentScreen), drawingTime);
                        drawChild(canvas, getChildAt(mNextScreen), drawingTime);
                    } else {
                        // If we are scrolling, draw all of our children
                        final int count = getChildCount();
                        for (int i = 0; i < count; i++) {
                         int select = AlmostNexusSettingsHelper.getAnimator(getContext());
                         if (select < 3){
                         drawChild(canvas, getChildAt(i), getDrawingTime());
                         }else{
                         getChildAt(i).invalidate();
                                drawScreen(canvas, i, getDrawingTime(), select);
                         }
                        }
                    }
                }
            } else {
                long currentTime;
                if (startTime == 0) {
                    startTime = SystemClock.uptimeMillis();
                    currentTime = 0;
                } else {
                    currentTime = SystemClock.uptimeMillis() - startTime;
                }
                if (currentTime >= mAnimationDuration) {
                    isAnimating = false;
                    if (mStatus == SENSE_OPENING) {
                        mStatus = SENSE_OPEN;
                    } else if (mStatus == SENSE_CLOSING) {
                        mStatus = SENSE_CLOSED;
                        mSensemode = false;
                        clearChildrenCache();
                        unlock();
                        postInvalidate();
                    }
                } else {
                    postInvalidate();
                }
                final int count = getChildCount();
                for (int i = 0; i < count; i++) {
                 int select = AlmostNexusSettingsHelper.getAnimator(getContext());
                 if (select < 3){
                    drawChild(canvas, getChildAt(i), getDrawingTime());
                 }else{
                 getChildAt(i).invalidate();
                        drawScreen(canvas, i, getDrawingTime(), select);
                 }
                }
            }
            if (restore) {
                canvas.restore();
            }
        }    /*add by dwj*/
    public void drawScreen(Canvas canvas, int screen, long drawingTime, int select) {
    int saveCount = canvas.save();
    getChildAt(screen).setAlpha(1);
    if (mSensemode) {
    View child = getChildAt(screen);
                if (isAnimating || mStatus == SENSE_OPEN) {
                    long currentTime = SystemClock.uptimeMillis() - startTime;
                    Rect r1 = new Rect(0, 0, child.getWidth(), child.getHeight());
                    RectF r2 = getScaledChild(child);
                    float x = 0;
                    float y = 0;
                    float width = 0;
                    float alpha = 255;
                    if (mStatus == SENSE_OPENING) {
                        alpha = easeOut(currentTime, 0, 100, mAnimationDuration);
                        x = easeOut(currentTime, child.getLeft(), r2.left, mAnimationDuration);
                        y = easeOut(currentTime, child.getTop(), r2.top, mAnimationDuration);
                        width = easeOut(currentTime, child.getRight(), r2.right, mAnimationDuration);
                    } else if (mStatus == SENSE_CLOSING) {
                        alpha = easeOut(currentTime, 100, 0, mAnimationDuration);
                        x = easeOut(currentTime, r2.left, child.getLeft(), mAnimationDuration);
                        y = easeOut(currentTime, r2.top, child.getTop(), mAnimationDuration);
                        width = easeOut(currentTime, r2.right, child.getRight(), mAnimationDuration);
                    } else if (mStatus == SENSE_OPEN) {
                        x = r2.left;
                        y = r2.top;
                        width = r2.right;
                        alpha = 100;
                    }
                    float scale = ((width - x) / r1.width());
                    canvas.save();
                    canvas.translate(x, y);
                    canvas.scale(scale, scale);
                    mPaint.setAlpha((int) alpha);
                    canvas.drawRoundRect(
                            new RectF(r1.left + 5, r1.top + 5, r1.right - 5, r1.bottom - 5), 15f, 15f,
                            mPaint);
                    mPaint.setAlpha(255);
                    child.draw(canvas);
                    canvas.restore();
                } else {
                    child.draw(canvas);
                }
    }else{
     if (select == 3) {  //旋转
    final int width = getWidth();
    final int scrollWidth = screen * width;
    final int scrollX = this.getScrollX();
    if (scrollWidth > scrollX + width || scrollWidth + width < scrollX) {
    return;
    }
    final View child = getChildAt(screen);
    final int faceIndex = screen;
    final float currentDegree = getScrollX() * (angle / getMeasuredWidth());
    final float faceDegree = currentDegree - faceIndex * angle;
    if (faceDegree > 90 || faceDegree < -90) {
    return;
    }
    final float centerX = (scrollWidth < scrollX) ? scrollWidth + width : scrollWidth;
    final float centerY = getHeight() / 2;
    final Camera camera = mCamera;
    final Matrix matrixX = mMatrix;
    canvas.save();
    camera.save();
    camera.rotateY(-faceDegree);
    camera.getMatrix(matrixX);
    camera.restore();
    matrixX.preTranslate(-centerX, -centerY);
    matrixX.postTranslate(centerX, centerY);
    canvas.concat(matrixX);
    drawChild(canvas, child, drawingTime);
    canvas.restore();
    } else {
                super.dispatchDraw(canvas);
            }
    }
            canvas.restoreToCount(saveCount);
            mLastScroll = getScrollX();
    }
      

  3.   

    弄了一天,这个问题还是自己解决了,但解决的办法没有什么技术含量,就是把自己写的动画加到workspace中的drawChild()中,这样的话,Launcher会自己处理滑动时手指离开屏幕后的动画绘制,我以前是自己的drawScreen()函数。但是Launcher到底是怎么处理手指离开后的动画,我还是不太清楚,希望有懂的高手解答,感激不尽!
      

  4.   

    有没有高手研究过Launcher呢?