今天是实现了一个小功能的东西。看看效果图:


实现方式:
1.自定义ScrollView   复写onScrollChange方法,来计算滑动的位置。
2.自定义接口,通过接口来在ScrollView中控制,滑动的高度的进度。
3.在自定义View中去执行动画。


代码实现:
1.ScrollView   最主要的代码只有计算滑动位置的代码了,其实也是很简单的,获取子View的个数,每次都去for循环,去计算字View的位置,以及当前ScrollView的top bottom
代码:

@Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        int currentBottom = t + height ;
        int currentTop = t ; 
        Log.e("Slide", "onScrollChange") ;
        
        for (int i = 0; i < childCount; i++) {
            View childView = contentLayout.getChildAt(i )  ;
            if (!(childView  instanceof EasySlideInter)) {
                continue ; 
            }
            int childTop = childView.getTop() ; 
            int childBottom = childView.getBottom() ;
            int childHeight = childView.getHeight() ; 
            EasySlideInter inter = (EasySlideInter) childView ; 
            if ( currentTop > childTop && currentTop < childBottom ) {
                inter.contentSlide(countProgress(currentTop, childBottom, childHeight)); 
            }else if (currentBottom > childTop && currentBottom < childBottom ) {
                inter.contentSlide(100 - countProgress(currentBottom, childBottom, childHeight)); 
            }else if(childTop >= currentTop && childBottom <= currentBottom){
                inter.resetContent();
            }
        }

}  



通过childView的top位置与ScrollView的当前的top位置来判断是哪个子View正在慢慢的出现,计算出progress 传递给子View中去。

其实最终要的代码就是这么一段,动画的执行都在子View的接口方法中去做的。
我贴上一个子View的实现:
    
    @Override
    public void contentSlide(int progress) {
        textAnimator.setCurrentPlayTime(progress);
        backAnimator.setCurrentPlayTime(progress);
    }
    @Override
    public void resetContent() {
        textAnimator.setCurrentPlayTime(100);
        backAnimator.setCurrentPlayTime(100);
    }
    
    
    private void initAnimation(){
        textAnimator = ObjectAnimator.ofInt(text, "textColor", Color.BLUE , Color.RED); 
        textAnimator.setEvaluator(new ArgbEvaluator());
        textAnimator.setDuration(100)  ;
        textAnimator.setInterpolator(new LinearInterpolator()) ;
        
        backAnimator = ObjectAnimator.ofInt(this, "backgroundColor", Color.BLACK , Color.BLUE , Color.BLACK); 
        backAnimator.setEvaluator(new ArgbEvaluator());
        backAnimator.setDuration(100)  ;
        backAnimator.setInterpolator(new LinearInterpolator()) ;
        

}  

实现两个接口的方法,在这两个方法中,去控制动画的进度。
很简单的,不再累赘叙述了。
源码下载:




附件列表

最新文章

  1. Markdown的使用---现学现用
  2. 【BZOJ1251】序列终结者 Splay
  3. gtest
  4. startup.c
  5. 前端里神奇的BFC 原理剖析
  6. Win10如何隐藏Windows Defender任务栏图标
  7. [设计模式]Netd中的命令设计模式
  8. Embedded Linux Primer----嵌入式Linux基础教程--2.4节--嵌入式Linux发行版
  9. ListActivity的注意点
  10. 利用Xtrabackup备份集合恢复一台从库的过程
  11. “MVC+Nhibernate+Jquery-EasyUI” 信息发布系统 第四篇(用户管理功能的实现)
  12. &lt;Video&gt; in HTML5
  13. win7 64位安装redis 及Redis Desktop Manager使用(转载的)
  14. 面试北京XX数通总结
  15. Android为TV端助力 deep link(深度链接)与自定义协议!
  16. Java语法基础学习DayEighteen(常用类)
  17. setfacl命令
  18. 用idea简单创建web项目——两种方式
  19. Linux----CentOS-7搭建免流服务器(iOS 端)
  20. 科学计算三维可视化---Mlab基础(常用控制函数)

热门文章

  1. 今日例子border
  2. libuv在cocos2d-x中的使用
  3. 携程Android App插件化和动态加载实践
  4. svchost占用内存达1-2G的问题
  5. 上海邮政EMS海关清关(个人) 流程
  6. HTTP请求报文和HTTP响应报文(转)
  7. Android 中的AIDL,Parcelable和远程服务
  8. javaweb 学习总结
  9. .NET错误The &#39;targetFramework&#39; attribute in the &lt;compilation&gt; element of the Web.config file is used only to target version 4.0 and later of the .NET Framework
  10. Scala 深入浅出实战经典 第61讲:Scala中隐式参数与隐式转换的联合使用实战详解及其在Spark中的应用源码解析