Gallery层叠自动切换效果


其中有两段核心源码,一是让Gallery产生层叠效果的部分:

01 privatevoid transformImageBitmap(BorderImageView child, Transformation t, floatrotationAngle) {
02         mCamera.save();
03         finalMatrix imageMatrix = t.getMatrix();
04         finalint imageHeight = child.getLayoutParams().height;
05         finalint imageWidth = child.getLayoutParams().width;
06         finalfloat rotation = Math.abs(rotationAngle);
07         floatzoomAmount = mMaxZoom + 2* rotation;
08   
09         //缩放比例,720P为1,1080P为1.5
10         floatscale = this.getContext().getResources().getInteger(R.integer.gallery_scale) / 10.0f;
11   
12         mCamera.translate((float) (rotationAngle * 2.8* scale), (float) (rotation * 0.1),
13                 zoomAmount);
14   
15         //设置透明度
16         child.setAlpha((int) (255- 255* 0.1* Math.pow(rotation / mMaxRotationAngle, 2)));
17   
18         //设置背景
19   
20         intpadding = (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         }elseif (rotation / mMaxRotationAngle == 2) {
27             child.setBorderColor(this.getContext().getResources()
28                     .getColor(R.color.layer_bottom_border));
29         }else{
30             child.setBorderColor(Color.TRANSPARENT);
31         }
32   
33         mCamera.getMatrix(imageMatrix);
34         imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
35         imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
36         mCamera.restore();
37   
38    }

二是控制图片渲染顺序的部分:
01 protectedint getChildDrawingOrder(intchildCount, inti) {
02         intselectedPos = this.getSelectedItemPosition();
03         if(childCount <= 2) {
04             returnsuper.getChildDrawingOrder(childCount, i);
05         }elseif (childCount == 3) {
06             if(selectedPos < (childCount / 2)) {
07                 returnchildCount - i - 1;
08             }else{
09                 returni;
10             }
11   
12         }elseif (childCount == 4) {
13             if(selectedPos < (childCount / 2)) {
14                 if(i < 1) {
15                     returni;
16                 }
17                 returnchildCount - i;
18             }else{
19                 if(i < (childCount / 2)) {
20                     returni;
21                 }
22                 return(childCount - i) + 1;
23             }
24   
25         }else{
26             if(i < (childCount / 2)) {
27                 returni;
28             }
29             return(childCount - i - 1) + (childCount / 2);
30         }
31    }

除此之外的代码应该没什么特别的,直接上源码吧,欢迎大家下载学习

demo下载

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值