一种实现视差效果的思路
2014-01-17 17:17
134 查看
private void onScrollChanged(int top) { if(scrollTop == top){ return; } scrollTop = top; //srollview当前显示高度 int scrollViewHeight = getHeight(); //srollview实际的总高度 int scrollViewBottom = getAbsoluteBottom(); int scrollViewHalfHeight = scrollViewHeight / 2; // starts at 1 because the first View is a static non Discrollvable // view. for(int index = 1; index < mContent.getChildCount() ; index++) { View child = mContent.getChildAt(index); if(! (child instanceof Discrollvable)) { //it's a static view, doesn't care about continue; } Discrollvable discrollvable = (Discrollvable) child; int discrollvableTop = child.getTop(); int discrollvableHeight = child.getHeight(); int discrollvableAbsoluteTop = discrollvableTop - top; Log("DiscrollView ------- index: ", ""+index, index); Log("DiscrollView ------- top: ", ""+top, index); Log("DiscrollView ------- scrollViewHeight: ", ""+scrollViewHeight, index); Log("DiscrollView ------- scrollViewBottom: ", ""+scrollViewBottom, index); Log("DiscrollView ------- discrollvableTop: ", ""+discrollvableTop, index); Log("DiscrollView ------- discrollvableHeight: ", ""+discrollvableHeight, index); Log("DiscrollView ------- discrollvableAbsoluteTop: ", ""+discrollvableAbsoluteTop, index); Log("DiscrollView ------- child.getBottom(): ", ""+child.getBottom(), index); Log("DiscrollView ------- scrollViewBottom - child.getBottom() ", ""+(scrollViewBottom - child.getBottom()), index); Log("DiscrollView ------- discrollvableHeight + scrollViewHalfHeight: ", ""+(discrollvableHeight + scrollViewHalfHeight), index); //原始需求:提供一个 让用户在浏览引导时看到各个“Discrollvable”的滑动视差动画 的因子 //尽可能的让用户从“Discrollvable”滑动到“ParentView”(此处是指的ScrollView)的显示中间,开始动画展示 //当“Discrollvable”的顶部滑动到“ParentView”(此处是指的ScrollView),完成动画展示 //哪些是定值,哪些是不定值 //这个算法都是围绕“top”这个不定值来产生“视差” //进一步分析:由此对于ScrollView中的“Discrollvable”分为两类, //一类可以满足原始需求的--即它的底部“剩余高度” 大于 它的本身高度加上ScrollView显示高度的一半 //形成视差:以每个“discrollvable”的实际高度作为“视差因子”的基数, //动画开始位置和“discrollvableAbsoluteTop”产生视差的变数. //the Discrollvable is too big to be discrollved when its center is reached //the Discrollvable center. Discrollve it by its top. if(scrollViewBottom - child.getBottom() < discrollvableHeight + scrollViewHalfHeight) { Log("DiscrollView *********** discrollvableAbsoluteTop", ""+discrollvableAbsoluteTop, index); //the Discrollvable top reaches the DiscrollView bottom if(discrollvableAbsoluteTop <= scrollViewHeight) { int visibleGap = scrollViewHeight - discrollvableAbsoluteTop; discrollvable.onDiscrollve(clamp(visibleGap / (float) discrollvableHeight, 0.0f, 1.0f)); } else { discrollvable.onResetDiscrollve(); } } else { Log("DiscrollView ########## discrollvableAbsoluteTop", ""+discrollvableAbsoluteTop, index); if(discrollvableAbsoluteTop <= scrollViewHalfHeight) { //the Discrollvable center reaches the DiscrollView center int visibleGap = scrollViewHalfHeight - discrollvableAbsoluteTop; discrollvable.onDiscrollve(clamp(visibleGap / (float) discrollvableHeight, 0.0f, 1.0f)); } else { discrollvable.onResetDiscrollve(); } } } }
参考Discrollview
相关文章推荐
- 一种快速毛玻璃虚化效果实现--Android
- 使用Node.js实现ORM的一种思路详解(图文)
- 利用CSS固定背景交替实现视差滚动效果
- Ajax删除效果的实现思路和注意细节
- 一个网页标题title的闪动提示效果实现思路
- 具有3D旋转效果的图片组的一种实现
- android 使用贝塞尔曲线实现“波浪”效果思路解析
- 滑动tableView表单时cell图片的视差效果实现分析
- 一种表格背景色渐变效果的实现
- 一种注册表沙箱的思路、实现——研究Reactos中注册表函数的实现1
- javascript淡入淡出效果的实现思路
- 视差滚动(Parallax Scrolling)效果的原理和实现
- AngularJS2中一种button切换效果的实现方法(二)
- (4.2.24)一种快速毛玻璃虚化效果实现
- 某些下拉刷新变波浪的效果实现思路
- Jquery实现图片放大镜效果的思路及代码
- 一种快速毛玻璃虚化效果实现
- Javascript+CSS实现影像卷帘效果思路及代码
- 一种简单的边界提取思路Matlab实现
- 视差滚动(Parallax Scrolling)效果的原理和实现