Android设计库25.1.0导致FloatingActionButton.Behavior停止工作 [英] Android design library 25.1.0 causes FloatingActionButton.Behavior to stop working
问题描述
我已经使用这个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){
//确保我们对垂直滚动做出反应
返回nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL
|| super.onStartNestedScroll(coordinatorLayout,child,directTargetChild,target,nestedScrollAxes);
@Override
public void onNestedScroll(final CoordinatorLayout coordinatorLayout,final FloatingActionButton child,
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){
//用户向下滚动,FAB当前可见 - >隐藏FAB
child.hide();
} else if(dyConsumed< 0&&&child.getVisibility()!= View.VISIBLE){
//用户向上滚动,FAB当前不可见 - >显示FAB
child.show();
}
}}
一旦我更新到支持库
编译'com.android.support:design:25.1.0'
pre>
FloatingActionButton.Behavior停止正常工作。它隐藏了FAB一次,然后再也没有被调用。不是onStartNestedScroll或onNestedScroll方法。
有没有人知道这里发生了什么。我的代码的其余部分保持不变,我只更新这个库,它将像以前一样停止工作。
解决方案对于
25.1.0
,CoordinatorLayout
在查找行为以调用其onNestedScroll
方法时跳过设置为GONE
的视图。
该解决方案正在以INVISIBLE
。替换FAB的可见性GONE
只需更改:child.hide();
to:
code> child.hide(new FloatingActionButton.OnVisibilityChangedListener(){
@Override
public void onHidden(FloatingActionButton fab){
super.onHidden(fab);
fab .setVisibility(View.INVISIBLE);
}
});
I've been using this FloatingActionButton.Behavior for many months now, it takes care of hiding and showing the FAB of my application. Never had an issue.
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(); } }}
As soon as I update to the support library
compile 'com.android.support:design:25.1.0'
the FloatingActionButton.Behavior stops working properly. It hides the FAB once and then it's never called again. Not the onStartNestedScroll or the onNestedScroll method.
Does anyone know what's happening here. The rest of my code remains unchanged, I only update this library and it stops working as before.
解决方案For
25.1.0
,CoordinatorLayout
is skipping views set toGONE
when looking for behaviors to call in itsonNestedScroll
method.
The solution is replacing FAB's visibilityGONE
withINVISIBLE
.
Simply, change:child.hide();
to:
child.hide(new FloatingActionButton.OnVisibilityChangedListener() { @Override public void onHidden(FloatingActionButton fab) { super.onHidden(fab); fab.setVisibility(View.INVISIBLE); } });
这篇关于Android设计库25.1.0导致FloatingActionButton.Behavior停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!