首页 > 移动开发 > Android 如何在Launcher的桌面滑动时添加动画效果? M

Android 如何在Launcher的桌面滑动时添加动画效果? M

目前的Launcher桌面滑动时,是没有动画的。如何在Lancher的桌面滑动时添加动画效果?Demo:

 

[java][/java] view plaincopyprint?

  1. 请修改Workspace.java的screenScrolled方法,如下:
  2.     @Override
  3.     protected void screenScrolled(int screenCenter) {
  4.         super.screenScrolled(screenCenter);
  5.         updatePageAlphaValues(screenCenter);
  6.         enableHwLayersOnVisiblePages();
  7.         if (mOverScrollX < 0 || mOverScrollX > mMaxScrollX) {
  8.             int index = mOverScrollX < 0 ? 0 : getChildCount() - 1;
  9.             CellLayout cl = (CellLayout) getChildAt(index);
  10.             float scrollProgress = getScrollProgress(screenCenter, cl, index);
  11.             cl.setOverScrollAmount(Math.abs(scrollProgress), index == 0);
  12.             float rotation = - WORKSPACE_OVERSCROLL_ROTATION * scrollProgress;
  13.             cl.setRotationY(rotation);
  14.             setFadeForOverScroll(Math.abs(scrollProgress));
  15.             if (!mOverscrollTransformsSet) {
  16.                 mOverscrollTransformsSet = true;
  17.                 cl.setCameraDistance(mDensity * mCameraDistance);
  18.                 cl.setPivotX(cl.getMeasuredWidth() * (index == 0 ? 0.75f : 0.25f));
  19.                 cl.setPivotY(cl.getMeasuredHeight() * 0.5f);
  20.                 cl.setOverscrollTransformsDirty(true);
  21.             }
  22.         } else {
  23.             if (mOverscrollFade != 0) {
  24.                 setFadeForOverScroll(0);
  25.             }
  26.             if (mOverscrollTransformsSet) {
  27.                 mOverscrollTransformsSet = false;
  28.                 ((CellLayout) getChildAt(0)).resetOverscrollTransforms();
  29.                 ((CellLayout) getChildAt(getChildCount() - 1)).resetOverscrollTransforms();
  30.             }
  31.             //mtk add (demo)
  32.             for (int i = 0; i < getChildCount(); i++) {
  33.                 View v = getPageAt(i);
  34.                 if (v != null) {
  35.                      float scrollProgress = getScrollProgress(screenCenter, v, i);
  36.                      float rotation = - WORKSPACE_OVERSCROLL_ROTATION * 5 * scrollProgress;
  37.                      v.setRotation(rotation);
  38.                      v.setCameraDistance(mDensity * mCameraDistance);
  39.                      v.setPivotX(v.getMeasuredWidth() * 0.5f);
  40.                      v.setPivotY(v.getMeasuredHeight());
  41.                  }
  42.             }
  43.             //mtk add (demo)
  44.         }
  45.     }

 

 

目前的Launcher桌面滑动时,是没有动画的。如何在Lancher的桌面滑动时添加动画效果?

本文固定链接: http://www.devba.com/index.php/archives/4026.html | 开发吧

报歉!评论已关闭.