我已经使用这个FloatingActionButton.Behavior好几个月了,它负责隐藏和显示我的应用程序的FAB.从未遇到过问题.
public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior { public ScrollAwareFABBehavior(Context context, AttributeSet attrs) { super(); } @Override public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child, final View directTargetChild, final View target, final int nestedScrollAxes) { // Ensure we react to vertical scrolling return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL || super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes); } @Override public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child, final View target, final int dxConsumed, final int dyConsumed, final int dxUnconsumed, final int dyUnconsumed) { super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed); if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) { // User scrolled down and the FAB is currently visible -> hide the FAB child.hide(); } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) { // User scrolled up and the FAB is currently not visible -> show the FAB child.show(); } }}
一旦我更新到支持库
compile 'com.android.support:design:25.1.0'
FloatingActionButton.Behavior停止正常工作.它隐藏了FAB一次然后它再也没有被调用过.不是onStartNestedScroll或onNestedScroll方法.
有谁知道这里发生了什么.我的其余代码保持不变,我只更新这个库,它像以前一样停止工作.
对于25.1.0
,CoordinatorLayout
正在跳过GONE
在查找其onNestedScroll
方法中要调用的行为时设置的视图.
该解决方案将取代FAB的知名度GONE
与INVISIBLE
.
简单地说,改变:
child.hide();
至:
child.hide(new FloatingActionButton.OnVisibilityChangedListener() { @Override public void onHidden(FloatingActionButton fab) { super.onHidden(fab); fab.setVisibility(View.INVISIBLE); } });
我有完全相同的问题,看起来'支持设计包'中有一个错误.我相信,我们现在唯一可以做的就是回滚到以前的版本之一.我决定使用以下内容:
compile 'com.android.support:design:25.0.1'