【开源】ListView3d

ListView3d

  •  https://github.com/renard314/ListView3d

    介绍:

    ListView的3d效果。原理是重写了ListView的drawChild方法,并且在该方法中变换mMatrix来实现3d效果。

    运行效果:

使用说明:

关键代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
private void prepareMatrix(final Matrix outMatrix, int distanceY, int r){
    //clip the distance
    final int d = Math.min(r, Math.abs(distanceY));
    //use circle formula
    final float translateZ = (float) Math.sqrt((r * r) - (d * d));
    //solve for t: d = r*cos(t)
    double radians = Math.acos((float) d / r);
    double degree = 90 - (180 / Math.PI) * radians;
    mCamera.save();
    mCamera.translate(0, 0, r-translateZ);
    mCamera.rotateX((float) degree);
    if (distanceY < 0) {
        degree = 360 - degree;
    }
    //mCamera.rotateY((float) degree);
    mCamera.getMatrix(outMatrix);
    mCamera.restore();
                                                               
    // highlight elements in the middle
    mPaint.setColorFilter(calculateLight((float) degree));
}

如果不想在Y方向上有rotate

注释掉://mCamera.rotateY((float) degree);

posted on 2015-03-30 11:20  wasdchenhao  阅读(89)  评论(0)    收藏  举报

导航