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

Android仿iPhone滚轮控件实现及源码分析

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

在629行到744行的代码是绘制图形,747行onTouchEvent()里面主要是调用了882行的justify()方法,用于调整画面,

  1. @Override  
  2.     public boolean onTouchEvent(MotionEvent event) {  
  3.         WheelAdapter adapter = getAdapter();  
  4.         if (adapter == null) {  
  5.             return true;  
  6.         }  
  7.           
  8.             if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {  
  9.             justify();  
  10.         }  
  11.         return true;  
  12.     }  
  1. /** 
  2.      * Justifies wheel 
  3.      */  
  4.     private void justify() {  
  5.         if (adapter == null) {  
  6.             return;  
  7.         }  
  8.           
  9.         lastScrollY = 0;  
  10.         int offset = scrollingOffset;  
  11.         int itemHeight = getItemHeight();  
  12.         boolean needToIncrease = offset > 0 ? currentItem < adapter.getItemsCount() : currentItem > 0;   
  13.         if ((isCyclic || needToIncrease) && Math.abs((float) offset) > (float) itemHeight / 2) {  
  14.             if (offset < 0)  
  15.                 offset += itemHeight + MIN_DELTA_FOR_SCROLLING;  
  16.             else  
  17.                 offset -= itemHeight + MIN_DELTA_FOR_SCROLLING;  
  18.         }  
  19.         if (Math.abs(offset) > MIN_DELTA_FOR_SCROLLING) {  
  20.             scroller.startScroll(0, 0, 0, offset, SCROLLING_DURATION);  
  21.             setNextMessage(MESSAGE_JUSTIFY);  
  22.         } else {  
  23.             finishScrolling();  
  24.         }  
  25.     }  
linux
相关资讯       Android源码 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款