AndroidTips — How to have multiple collapsing layout by using NestedScrollCoordinatorLayout

Room Android version 3.0.1
Rakuten Room Android Preview
scroll|exitUnitlCollapsed for image area, scoll|enterAlway for tabLayout area
  1. AppbarLayout child don’t have to be CollapsingToolbarLayout in order to be collapsible
  2. Cannot put AppbarLayout children “scroll|enterAlways” view at the bottom of “scroll|exitUntilCollapsed” view, or else the “scroll|enterAlways” view won’t have any effect.
    Below is the few example of the combination :
    a. “scroll” for image and “scroll|enterAlways” for TabLayout works well to let the TabLayout half floating, but not for the header part being sticky
    https://gist.github.com/kelvinc1024/22e6c6ec46eb04849f0efa0f7629616c
“scroll” for image & “scroll|enterAlways” for tabLayout
“scroll|exitUntilCollapsed” for image & “scroll|enterAlways” for tabLayout

The idea of using nested scroll CoordinatorLayout

Nesting CoordinatorLayout inside CoordinatorLayout

So how can we handle it so parent can scroll properly?

This interface should be implemented by View subclasses that wish to support dispatching nested scrolling operations to a cooperating parent ViewGroup.Classes implementing this interface should create a final instance of a NestedScrollingChildHelper as a field and delegate any View methods to the NestedScrollingChildHelper methods of the same signature.Views invoking nested scrolling functionality should always do so from the relevant ViewCompat, ViewGroupCompat or ViewParentCompat compatibility shim static methods. This ensures interoperability with nested scrolling views on all versions of Android.
@Override
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed, int type) {
dispatchNestedPreScroll(dx, dy, consumed, null);
if (consumed[1] == 0) { //if still not zero, not to resume the scroll to this NestedCoordinatorLayout
super.onNestedPreScroll(target, dx, dy, consumed, type);
}
}

--

--

--

Android Engineer at Rakuten

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

CI/CD with Maven, GitHub, Docker & Jenkins

What is KUTTL?

Random Number Generation In Various Programming Languages

MERGE SORT

Dagger 2 ( Caution: PLEASE TRY AT HOME ) Part 5

Using Dolly Track in Unity

Intro to SQL User-Defined Functions: A Redshift UDF Tutorial

Handling errors in gRPC and go-kit services

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kelvin Chandra

Kelvin Chandra

Android Engineer at Rakuten

More from Medium

Object-Oriented Programming(OOP) (Make Kotlin syntax as an example):

Play different .wav files one after another

Link C/C++ library dependencies to your own C/C++ code in an Android application using CMake

Sophixticated Joker