Floating action button not visible on scrolling after updating Google Support & Design Library

后端 未结 3 732
挽巷
挽巷 2020-12-29 22:59

I\'ve tried updating com.android.support:appcompat and com.android.support:design from: 25.0.1 to 25.1.0, as follows:

compile \'com         


        
相关标签:
3条回答
  • 2020-12-29 23:36

    Updating from support lib 25.0.1 to 25.1.0 changes the onNestedScroll method of CoordinatorLayout in that the call is skipped for views whose visibility is set to View.GONE.

    Calling child.hide() on the floating action button sets the view's visibility to View.GONE, which means now (as of 25.1.0), the onNestedScroll method call will be skipped for the floating action button in the future (because it skips all views whose visibility is GONE).

    A workaround for this would be to set the view's visibility to INVISIBLE whenever you hide it. This way, the onNestedScroll will not skip the view the next time a nested scroll is performed.

    In order to achieve this, you can call

    child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
                /**
                 * Called when a FloatingActionButton has been hidden
                 *
                 * @param fab the FloatingActionButton that was hidden.
                 */
                @Override
                public void onHidden(FloatingActionButton fab) {
                    super.onShown(fab);
                    fab.setVisibility(View.INVISIBLE);
                }
            });
    

    in your onNestedScroll method.

    Edit: This issue has been submitted to the AOSP Issue Tracker at https://code.google.com/p/android/issues/detail?id=230298

    0 讨论(0)
  • 2020-12-29 23:44

    in CoordinatorLayout 25.1.0 (

       for (int i = 0; i < childCount; i++) {
                final View view = getChildAt(i);
                if (view.getVisibility() == GONE) {
                    // If the child is GONE, skip...
                    continue;
                }
    

    in 25.0.1

    for (int i = 0; i < childCount; i++) {
                final View view = getChildAt(i);
                final LayoutParams lp = (LayoutParams) view.getLayoutParams();
                if (!lp.isNestedScrollAccepted()) {
                    continue;
                }
    
                final Behavior viewBehavior = lp.getBehavior();
                if (viewBehavior != null) {
                    viewBehavior.onNestedScroll(this, view, target, dxConsumed, dyConsumed,
                            dxUnconsumed, dyUnconsumed);
                    accepted = true;
    
            }
    
    0 讨论(0)
  • 2020-12-29 23:45

    The behavior has changed since support lib version 25.1.0.

    It must be the RecyclerView (Behavior) that triggers the FAB visibility change.

    In other words, it's no longer the responsibility of the object that wants to react to have a behavior but on the object that moves to be aware of everything on screen.

    Below is a link to a diff that shows the changes that are required to perform the upgrade:

    https://github.com/chrisbanes/cheesesquare/compare/master...ianhanniballake:scroll_aware_fab

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