onNestedScroll called only once

后端 未结 5 1188
面向向阳花
面向向阳花 2021-02-06 06:30

I have a class

public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior {
    public ScrollAwareFABBehavior(Context context, AttributeSet attrs         


        
相关标签:
5条回答
  • 2021-02-06 07:00

    Do not set the visibility of FAB to GONE in child.hide() - use INVISIBLE instead. From 25.1.0, the scroll events are not passed on to views whose visibility is GONE

    0 讨论(0)
  • 2021-02-06 07:07
    @Override
    public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull FloatingActionButton child, @NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) {
        super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type);
        if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
            child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
                @Override
                public void onHidden(FloatingActionButton fab) {
                    super.onHidden(fab);
                    fab.setVisibility(View.INVISIBLE);
                }
            });
        } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
            child.show();
        }
    }
    
    0 讨论(0)
  • 2021-02-06 07:16

    I solved the problem changing the visibility from GONE to INVISIBLE with the following code.

     @Override
    public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child,
                               View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
        super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed,
                dyUnconsumed);
    
        if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
            child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
                @Override
                public void onShown(FloatingActionButton fab) {
                    super.onShown(fab);
                }
    
                @Override
                public void onHidden(FloatingActionButton fab) {
                    super.onHidden(fab);
                    fab.setVisibility(View.INVISIBLE);
                }
            });
        } else if (dyConsumed <= 0 && child.getVisibility() != View.VISIBLE) {
            child.show();
        }
    }
    
    0 讨论(0)
  • 2021-02-06 07:16

    I have just answered to absolutely the same problem in another post, check it.

    Speaking shortly, use the following:

    compile 'com.android.support:design:25.0.1'
    
    0 讨论(0)
  • 2021-02-06 07:19

    For me i replace child.hide() with ((View)child).setVisibility(View.INVISIBLE).

    0 讨论(0)
提交回复
热议问题