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

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

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

主要的方法就是:

  1. //控制gallery中每个图片的旋转(重写的gallery中方法)   
  2.     protected boolean getChildStaticTransformation(View child, Transformation t) {    
  3.         //取得当前子view的半径值   
  4.         final int childCenter = getCenterOfView(child);         
  5.         final int childWidth = child.getWidth();  
  6.         //旋转角度   
  7.         int rotationAngle = 0;  
  8.         //重置转换状态   
  9.         t.clear();  
  10.         //设置转换类型   
  11.         t.setTransformationType(Transformation.TYPE_MATRIX);  
  12.         //如果图片位于中心位置不需要进行旋转   
  13.         if (childCenter == mCoveflowCenter) {  
  14.             transformImageBitmap((ImageView) child, t, 0);  
  15.         } else {  
  16.             //根据图片在gallery中的位置来计算图片的旋转角度   
  17.             rotationAngle = (int) (((float) (mCoveflowCenter - childCenter) / childWidth) * mMaxRotationAngle);  
  18.             System.out.println("rotationAngle:" +rotationAngle);  
  19.             //如果旋转角度绝对值大于最大旋转角度返回(-mMaxRotationAngle或mMaxRotationAngle;)   
  20.             if (Math.abs(rotationAngle) > mMaxRotationAngle) {  
  21.                 rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle : mMaxRotationAngle;  
  22.             }  
  23.             transformImageBitmap((ImageView) child, t, rotationAngle);  
  24.         }  
  25.         return true;  
  26.     }  

先根据图片所处的位置计算出需要旋转的角度,然后进行旋转:

  1. //根据图片在gallery中的位置来计算图片的旋转角度   
  2.          rotationAngle = (int) (((float) (mCoveflowCenter - childCenter) / childWidth) * mMaxRotationAngle);  
  3.          System.out.println("rotationAngle:" +rotationAngle);  
  4.          //如果旋转角度绝对值大于最大旋转角度返回(-mMaxRotationAngle或mMaxRotationAngle;)   
  5.          if (Math.abs(rotationAngle) > mMaxRotationAngle) {  
  6.              rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle : mMaxRotationAngle;  
  7.          }  
  8.          transformImageBitmap((ImageView) child, t, rotationAngle);  
linux
相关资讯       Android源码 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

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