Android 滑动效果进阶篇(六)—— 倒影效果

               

上篇介绍了使用Animation实现3D动画旋转翻页效果,现在介绍图片倒影实现,先看效果图


本示例主要通过自定义Gallery和ImageAdapter(继承自BaseAdapter)实现


1、倒影绘制

ImageAdapter继承自BaseAdapter,详细实现可见 Android 滑动效果入门篇(二)—— Gallery 这里重点介绍倒影原理及实现

倒影原理:

倒影效果是主要由原图+间距+倒影三部分组成,高度大约为原图的3/2(原图为1、倒影为1/2)

原图,就是我们看到了最开始的图片

间距,是原图与倒影之间的间隙,如:reflectionGap = 4;

倒影,是原图下半部分1/2高度,通过矩阵变换matrix.preScale(1, -1); 获取倒立图片,然后再加上线性遮罩和阴影实现


倒影实现:

 /** 反射倒影 */ public boolean createReflectedImages() {  final int reflectionGap = 4;  int index = 0;  for (Map<String, Object> map : list) {   Integer id = (Integer) map.get("image");   Bitmap originalImage = BitmapFactory.decodeResource(mContext.getResources(), id); // 获取原始图片   int width = originalImage.getWidth();   int height = originalImage.getHeight();   Matrix matrix = new Matrix();   matrix.preScale(1, -1);   // 图片矩阵变换(从低部向顶部的倒影)   Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height/2, width, height/2, matrix, false); // 截取原图下半部分   Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888);   // 创建倒影图片(高度为原图3/2)   Canvas canvas = new Canvas(bitmapWithReflection); // 绘制倒影图(原图 + 间距 + 倒影)   canvas.drawBitmap(originalImage, 0, 0, null);  // 绘制原图   Paint paint = new Paint();   canvas.drawRect(0, height, width, height + reflectionGap, paint);  // 绘制原图与倒影的间距   canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); // 绘制倒影图   paint = new Paint();   LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, Ti
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值