In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to achieve nested scrolling in Android related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this Android article on how to achieve nested scrolling, let's take a look.
The business requirements are:
VT container scrolls
Book covers can be scrolled and parallax
When the VT container scrolls to the top, scroll through the list, and scrolling connects.
When the list scrolls to the top, you can scroll the book cover and the VT container, and scroll to connect
The logic is clear, and then it depends on how to implement it. Before android5, we had no choice but to intercept events and handle them ourselves, but in a later version, android introduced the NestingScroll mechanism, which made life much easier for developers, and android provides a very good container class: CoordinatorLayout, which greatly simplifies the work of developers. Of course, we also need to put energy into learning and using these new Api.
Of course, we also need to know how we can achieve these effects without these API. So this article will achieve this effect in three ways:
Pure event interception and dispatch scheme
Implementation Scheme based on NestingScroll Mechanism
Implementation based on CoordinatorLayout and Behavior
The sample code is placed on Github, and you can view it by combining clone with articles.
Pure event interception and dispatch scheme
This is the most original plan, and of course it is flexible. Other schemes are based on the encapsulation provided by the system in principle. When using this scheme, we need to solve the following problems:
Scrolling of view (Scroller)
Speed tracking of view (VelocityTracker)
How do we pass events to ListView when the VT container scrolls to the top?
How does the VT container intercept events when ListView scrolls to the top?
1 and 2 two points belong to the basic knowledge of scrolling, which will not be explained in detail here. Why does the third point appear? Because when the android system dispatches the event, if the event is intercepted, then the subsequent events will not be passed to the sub-view. The solution is also simple: proactively dispatch a Down event when scrolling to the top:
If (mTargetCurrentOffset + dy = 0) {moveTargetView (dy);} else {if (mTargetCurrentOffset + dy = mTargetInitOffset) {headerTarget = mHeaderInitOffset;} else if (mTargetCurrentOffset 0) {/ / trigger fling downwards, you need to scroll to Init position mNeedScrollToInitPos = true MScroller.fling (0, mTargetCurrentOffset, 0, vy, 0,0, mTargetEndOffset, Integer.MAX_VALUE); invalidate ();} else if (vy < 0) {/ / up trigger fling, need to scroll to End position mNeedScrollToEndPos = true; mScroller.fling (0, mTargetCurrentOffset, 0, vy, 0,0, mTargetEndOffset, Integer.MAX_VALUE); invalidate () } else {/ / does not trigger fling, proximity principle if (mTargetCurrentOffset
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.