文件名称:带有倒影的Gallery
文件大小:749KB
文件格式:RAR
更新时间:2016-05-18 10:45:04
倒影Gallery
带有倒影的图片滑动效果,注释非常详细。 部分代码如下: for (int imageId : mImageIds) { Bitmap originalImage = BitmapFactory.decodeResource(mContext .getResources(), imageId); int width = originalImage.getWidth(); int height = originalImage.getHeight(); //设置图片反转 Matrix matrix = new Matrix(); // matrix.setRotate(30); //缩放图片的动作。矩阵前乘 // 1表示放大比例,不放大也不缩小。 // -1表示在y轴上相反,即旋转180度。 matrix.preScale(1, -1); //reflectionImage就是下面那个透明的倒影,宽为图片本来的宽度,高是图片高度的一半 //从height/2的高度开始到高度为(height/2)+(height/4) Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 4, matrix, false); //创建一个新的Bitmap高度为原来的1.5倍 Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); //先画原始的图片 Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(originalImage, 0, 0, null); Paint deafaultPaint = new Paint(); // 抗锯齿的方法 // deafaultPaint.setAntiAlias(true); //画图片与倒影之间的间距 canvas.drawRect(0, height, width, height + reflectionGap, deafaultPaint); //画倒影 canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); Paint paint = new Paint(); // 抗锯齿的方法 // paint.setAntiAlias(true); //创建一个渐变的模板放在下面被反转的图片上面 LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); ImageView imageView = new ImageView(mContext); imageView.setImageBitmap(bitmapWithReflection); imageView.setLayoutParams(new GalleryFlow.LayoutParams(180, 240)); // imageView.setScaleType(ScaleType.MATRIX); mImages[index++] = imageView; } return true; }
【文件预览】:
Gallery
----.project(845B)
----project.properties(562B)
----src()
--------com()
----AndroidManifest.xml(636B)
----res()
--------drawable-ldpi()
--------drawable-hdpi()
--------drawable()
--------drawable-mdpi()
--------layout()
--------drawable-xhdpi()
--------values()
----.settings()
--------org.eclipse.jdt.core.prefs(177B)
----assets()
----gen()
--------com()
----.classpath(364B)
----bin()
--------resources.ap_(278KB)
--------1-Gallery.apk(286KB)
--------classes()
--------AndroidManifest.xml(636B)
--------dexedLibs()
--------jarlist.cache(119B)
--------res()
--------classes.dex(11KB)