嗯,这篇文章是接着上一篇的,因为需求“变”了。上一篇文章中已经实现了滑动动画效果,现在需求变为:当停止滑动时,判断当前状态,若满足一个阈值就直接展开或者收起,也就是动画进度为 0 或 1 的状态。
如果只是单纯这种展开或者收起的效果,使用 layout_scrollFlags 的 snap 效果即可实现。layout_scrollFlags 有 5 种效果,摘录一片博客中的内容:
- scroll
The view will be scroll in direct relation to scroll events. This flag needs to be set for any of the other flags to take effect. If any sibling views before this one do not have this flag, then this value has no effect.
Child View 伴随着滚动事件而滚出或滚进屏幕。注意两点:第一点,如果使用了其他值,必定要使用这个值才能起作用;第二点:如果在这个 Child View 前面的任何其他 Child View 没有设置这个值,那么这个 Child View 的设置将失去作用。
more >>