其中有两段核心源码,一是让Gallery产生层叠效果的部分:
01 | private void transformImageBitmap(BorderImageView child, Transformation t, float rotationAngle) { |
03 | final Matrix imageMatrix = t.getMatrix(); |
04 | final int imageHeight = child.getLayoutParams().height; |
05 | final int imageWidth = child.getLayoutParams().width; |
06 | final float rotation = Math.abs(rotationAngle); |
07 | float zoomAmount = mMaxZoom + 2 * rotation; |
10 | float scale = this .getContext().getResources().getInteger(R.integer.gallery_scale) / 10 .0f; |
12 | mCamera.translate(( float ) (rotationAngle * 2.8 * scale), ( float ) (rotation * 0.1 ), |
16 | child.setAlpha(( int ) ( 255 - 255 * 0.1 * Math.pow(rotation / mMaxRotationAngle, 2 ))); |
20 | int padding = ( int ) Math.abs(mMaxRotationAngle * 0 .1f * scale); |
21 | child.setBorderwidth(padding); |
22 | child.setBorderRadius(padding); |
23 | if (rotation / mMaxRotationAngle == 1 ) { |
24 | child.setBorderColor( this .getContext().getResources() |
25 | .getColor(R.color.layer_middle_border)); |
26 | } else if (rotation / mMaxRotationAngle == 2 ) { |
27 | child.setBorderColor( this .getContext().getResources() |
28 | .getColor(R.color.layer_bottom_border)); |
30 | child.setBorderColor(Color.TRANSPARENT); |
33 | mCamera.getMatrix(imageMatrix); |
34 | imageMatrix.preTranslate(-(imageWidth / 2 ), -(imageHeight / 2 )); |
35 | imageMatrix.postTranslate((imageWidth / 2 ), (imageHeight / 2 )); |
二是控制图片渲染顺序的部分:
01 | protected int getChildDrawingOrder( int childCount, int i) { |
02 | int selectedPos = this .getSelectedItemPosition(); |
04 | return super .getChildDrawingOrder(childCount, i); |
05 | } else if (childCount == 3 ) { |
06 | if (selectedPos < (childCount / 2 )) { |
07 | return childCount - i - 1 ; |
12 | } else if (childCount == 4 ) { |
13 | if (selectedPos < (childCount / 2 )) { |
19 | if (i < (childCount / 2 )) { |
22 | return (childCount - i) + 1 ; |
26 | if (i < (childCount / 2 )) { |
29 | return (childCount - i - 1 ) + (childCount / 2 ); |
除此之外的代码应该没什么特别的,直接上源码吧,欢迎大家下载学习
demo下载