主要的方法就是:
- //控制gallery中每个图片的旋转(重写的gallery中方法)
- protected boolean getChildStaticTransformation(View child, Transformation t) {
- //取得当前子view的半径值
- final int childCenter = getCenterOfView(child);
- final int childWidth = child.getWidth();
- //旋转角度
- int rotationAngle = 0;
- //重置转换状态
- t.clear();
- //设置转换类型
- t.setTransformationType(Transformation.TYPE_MATRIX);
- //如果图片位于中心位置不需要进行旋转
- if (childCenter == mCoveflowCenter) {
- transformImageBitmap((ImageView) child, t, 0);
- } else {
- //根据图片在gallery中的位置来计算图片的旋转角度
- rotationAngle = (int) (((float) (mCoveflowCenter - childCenter) / childWidth) * mMaxRotationAngle);
- System.out.println("rotationAngle:" +rotationAngle);
- //如果旋转角度绝对值大于最大旋转角度返回(-mMaxRotationAngle或mMaxRotationAngle;)
- if (Math.abs(rotationAngle) > mMaxRotationAngle) {
- rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle : mMaxRotationAngle;
- }
- transformImageBitmap((ImageView) child, t, rotationAngle);
- }
- return true;
- }
先根据图片所处的位置计算出需要旋转的角度,然后进行旋转:
- //根据图片在gallery中的位置来计算图片的旋转角度
- rotationAngle = (int) (((float) (mCoveflowCenter - childCenter) / childWidth) * mMaxRotationAngle);
