Skip to content Skip to sidebar Skip to footer

Appbarlayout.scrollingviewbehavior - Bottom Of View Off Screen

When using an AppBarLayout with the standard ScrollingViewBehavior, the AppBarLayout's sibling will by default be the height of the CoordinatorLayout and the sibling's bottom will

Solution 1:

The solution I found to this issue involves 2 parts.

  1. Add padding equal to the height of the AppBarLayout to the BOTTOM of the NestedScrollView. In my case because the AppBarLayout only contained a Toolbar, the height was ?attr/actionBarSize. android:paddingBottom="?attr/actionBarSize"

  2. Adding a custom AppBarLayout.OnOffsetChangedListener to the AppBarLayout which changes the height of the NestedScrollView as the toolbar is collapsed.

    classScrollingOffsetFixListener(
        privateval nestedScrollView: NestedScrollView
    ): AppBarLayout.OnOffsetChangedListener {
    
    privatevar originalHeight = 0privatevar firstOffset = trueoverridefunonOffsetChanged(layout: AppBarLayout?, offset: Int) {
        if(firstOffset) {
            firstOffset = false
            originalHeight = nestedScrollView.measuredHeight
        }
    
        val params = nestedScrollView.layoutParams
        params.height = originalHeight + (offset * -1)
    
        nestedScrollView.layoutParams = params
       }
    }
    

Post a Comment for "Appbarlayout.scrollingviewbehavior - Bottom Of View Off Screen"