你好,游客 登录 注册 搜索
背景:
阅读新闻

Android自定义带倒影和偏转的超炫Gallery

[日期:2012-06-18] 来源:Linux社区  作者:aomandeshangxiao [字体:大 中 小]

主要功能实现是在transformImageBitmap()这个方法:

  1. private void transformImageBitmap(ImageView child, Transformation t,  
  2.                     int rotationAngle) {  
  3.         //对效果进行保存   
  4.         mCamera.save();  
  5.         final Matrix imageMatrix = t.getMatrix();  
  6.         //图片高度   
  7.         final int imageHeight = child.getLayoutParams().height;  
  8.         //图片宽度   
  9.         final int imageWidth = child.getLayoutParams().width;  
  10.           
  11.         //返回旋转角度的绝对值   
  12.         final int rotation = Math.abs(rotationAngle);  
  13.           
  14.         // 在Z轴上正向移动camera的视角,实际效果为放大图片。   
  15.         // 如果在Y轴上移动,则图片上下移动;X轴上对应图片左右移动。   
  16.         mCamera.translate(0.0f, 0.0f, 100.0f);  
  17.         // As the angle of the view gets less, zoom in   
  18.         if (rotation < mMaxRotationAngle) {  
  19.             float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));  
  20.             mCamera.translate(0.0f, 0.0f, zoomAmount);  
  21.         }  
  22.         // 在Y轴上旋转,对应图片竖向向里翻转。   
  23.         // 如果在X轴上旋转,则对应图片横向向里翻转。   
  24.         mCamera.rotateY(rotationAngle);  
  25.         mCamera.getMatrix(imageMatrix);  
  26.         imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));  
  27.         imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));  
  28.         mCamera.restore();  
  29.     }  

主要进行翻转操作。

关于滑动速度的修改需要重写onFling这个方法,如果想滑动一次只切换一张图片,可以试一下下面这个方法:

  1. private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {    
  2.         return e2.getX() > e1.getX();    
  3.     }    
  4.     
  5.     @Override    
  6.     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {    
  7.         // e1是按下的事件,e2是抬起的事件     
  8.         int keyCode;    
  9.         if (isScrollingLeft(e1, e2)) {    
  10.             keyCode = KeyEvent.KEYCODE_DPAD_LEFT;    
  11.         } else {    
  12.             keyCode = KeyEvent.KEYCODE_DPAD_RIGHT;    
  13.         }    
  14.         onKeyDown(keyCode, null);    
  15.         return true;    
  16.     }    

只是简单的把onFling里面的滑动转换为了点击物理左右方向键。

最后,下载地址:

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2012年资料/6月/18日/Android自定义带倒影和偏转的超炫Gallery/

linux
相关资讯       Android源码 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* 匿名 发表于 2013/10/9 10:23:10
能不能把你的xml布局代码也发出来啊!