This repository has been archived by the owner on Feb 19, 2021. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题原因
ViewPager 切换时,Fab 调用了 hide() 方法。
如果 Fab 尚未完全隐藏时,ViewPager 再次切换,则 Fab 会忽略此次 hide() 操作。(可参看 FloatingActionButtonIcs 源码中 isOrWillBeHidden() 方法和 mAnimState属性。)
而 Fab 的 onHidden() 回调中,使用的 position 被 final 修饰,导致快速切换时,回调中的 position 可能与当前不符,最终导致 ViewPager 快速切换时,Fab可能出现状态不对的问题。
解决方案
使用内部类替换 FloatingActionButton.OnVisibilityChangedListener 的匿名内部类,避免 position 被 final
修饰。