今天是实现了一个小功能的东西。看看效果图:实现方式: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( - 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(); backAnimator.setCurrentPlayTime(); } private void initAnimation(){ textAnimator = ObjectAnimator.ofInt(text, "textColor", Color.BLUE , Color.RED); textAnimator.setEvaluator(new ArgbEvaluator()); textAnimator.setDuration() ; textAnimator.setInterpolator(new LinearInterpolator()) ; backAnimator = ObjectAnimator.ofInt(this, "backgroundColor", Color.BLACK , Color.BLUE , Color.BLACK); backAnimator.setEvaluator(new ArgbEvaluator()); backAnimator.setDuration() ; backAnimator.setInterpolator(new LinearInterpolator()) ; } 实现两个接口的方法,在这两个方法中,去控制动画的进度。很简单的,不再累赘叙述了。源码下载:百度网盘: github地址 :
推荐整理分享随着ScrollView的滑动,渐渐的执行动画View(scrollview怎么用),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:scrollview实现原理,scrollview控件,scroll-view组件用于实现,scrollview可以直接包含多少个组件,scroll-view组件用于实现,scrollview可以直接包含多少个组件,scrollview实现原理,scrollview属性,内容如对您有帮助,希望把文章链接给更多的朋友!
![随着ScrollView的滑动,渐渐的执行动画View(scrollview怎么用)](https://www.jiuchutong.com/image/20240129/1706503147.jpg)
版权声明:本文为博主原创文章,未经博主允许不得转载。
android自定义之 5.0 风格progressBar 最近做项目,用到了ProgressBar,就想到了要使用Android5.0的效果,就随手实现了一下。效果图:大概的思路:1.圆圈通过Canvas去绘制2.圆圈的动画通过Animato
Intent启动系统组件(activity,service,BroadReceiver)-android学习之旅(四十九) android提供了统一的编程模型Intent来启动系统的组件,这样提供了松耦合性,是一种mvc的编程模式版权声明:本文为博主原创文章,未经博主允许不得转
Android学习【Android内核编译流程和错误笔记】 博客: