Android图片倒影效果和图片翻转旋转源代码下载
2015-02-05 12:59:10 By: shinyuu
本例子主要实现了Gallery特效、其主要功能是倒影效果和滑动翻转Gallery、可用于图片演示等功能点、效果非常不错、虽然说Gallery到目前为止Google已经不建议使用了、但毕竟是一种方法、仍然是可以正常使用的哈、没有任何影响、先看看效果图吧
代码也非常简单、内部已经封装好了、如果大家不喜欢这种效果、也可根据自己的需求进行更改、代码内部是通过自定义Gallery、然后再通过一个Adapter来实现的、在你自己的Activity里面你只需要简单的调用就可以了
onCreate代码
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_gallery); Integer[] images = { R.drawable.img0001, R.drawable.img0030, R.drawable.img0100, R.drawable.img0130, R.drawable.img0200, R.drawable.img0230, R.drawable.img0300, R.drawable.img0330, R.drawable.img0354 }; GalleryAdapter adapter = new GalleryAdapter(this, images); adapter.createReflectedImages(); GalleryView galleryFlow = (GalleryView) findViewById(R.id.Gallery01); galleryFlow.setAdapter(adapter); }
下面是倒影核心代码
private void transformImageBitmap(ImageView child, Transformation t, int rotationAngle) { mCamera.save(); final Matrix imageMatrix = t.getMatrix(); final int imageHeight = child.getLayoutParams().height; final int imageWidth = child.getLayoutParams().width; final int rotation = Math.abs(rotationAngle); // 在Z轴上正向移动camera的视角,实际效果为放大图片。 // 如果在Y轴上移动,则图片上下移动;X轴上对应图片左右移动。 mCamera.translate(0.0f, 0.0f, 100.0f); // As the angle of the view gets less, zoom in if (rotation < mMaxRotationAngle) { float zoomAmount = (float) (mMaxZoom (rotation * 1.5)); mCamera.translate(0.0f, 0.0f, zoomAmount); } // 在Y轴上旋转,对应图片竖向向里翻转。 // 如果在X轴上旋转,则对应图片横向向里翻转。 mCamera.rotateY(rotationAngle); mCamera.getMatrix(imageMatrix); imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2)); imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2)); mCamera.restore(); }
最后把Demo的源代码贴上、有兴趣的哥们可以下载研究研究
源代码链接: http://dwtedx.com/download.html?bdkey=s/1pJ8z6yf 密码: 4rz5
若资源对你有帮助、浏览后有很大收获、不妨小额打赏我一下、你的鼓励是维持我不断写博客最大动力
想获取DD博客最新代码、你可以扫描下方的二维码、关注DD博客微信公众号(ddblogs)
或者你也可以关注我的新浪微博、了解DD博客的最新动态:DD博客官方微博(dwtedx的微博)
如对资源有任何疑问或觉得仍然有很大的改善空间、可以对该博文进行评论、希望不吝赐教
为保证及时回复、可以使用博客留言板给我留言: DD博客留言板(dwtedx的留言板)
感谢你的访问、祝你生活愉快、工作顺心、欢迎常来逛逛