实现Launcher3的立方滚动特效

packages\apps\Launcher3\src\com\android\launcher3\PagedView.java 


@Override

    protected void dispatchDraw(Canvas canvas) {
if(this instanceof AppsCustomizePagedView){
if(getChildCount() <= 0 )return;


final long drawingTime = getDrawingTime();
   final int count = getChildCount();
       for (int i = 0; i < count; i++) {

                            drawScreenCube(canvas, i, drawingTime,4);
}
return;

}

}


 void drawScreenCube(Canvas canvas, int screen, long drawingTime ,int select) {

 final int width = getWidth(); 
System.out.println("width --- " + getWidth());
            final int scrollWidth = screen * width; 
            final int scrollX = this.getScrollX();  
            if(scrollWidth > scrollX + width || scrollWidth + width < scrollX) { 
                return; 
            } 
            final View child = getPageAt(screen); 
            final int faceIndex = screen; 
float faceDegree ;
            faceDegree =  (this.getScrollX() - faceIndex *width)*180/width/2;
       final float currentDegree = getScrollX() * (angle / getMeasuredWidth());
            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 matrix = mMatrix; 
            canvas.save(); 
            camera.save(); 
            camera.rotateY(-faceDegree); 
            camera.getMatrix(matrix); 
            camera.restore(); 
            matrix.preTranslate(-centerX, -centerY); 
            matrix.postTranslate(centerX, centerY); 
            canvas.concat(matrix); 
            drawChild(canvas, child, drawingTime);
            canvas.restore(); 
}

你可能感兴趣的:(android系统开发)