How can I create a half-expanded toolbar? Something like that WhatsApp profile page.
I've tried scrollBy
and scrollTo
, but they don't seem to work.
Even dispatchNestedScroll
, onNesterScroll
and onNestedPreScroll
don't seem to work.
How can I create a half-expanded toolbar? Something like that WhatsApp profile page.
I've tried scrollBy
and scrollTo
, but they don't seem to work.
Even dispatchNestedScroll
, onNesterScroll
and onNestedPreScroll
don't seem to work.
I managed to solve this problem by adapting this answer: https://stackoverflow.com/a/34920495/5369519 and using the following code:
nestedScrollView.post(() -> {
int appBarHeight = appBar.getHeight()/2;
nestedScrollView.startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
nestedScrollView.dispatchNestedPreScroll(0, appBarHeight, null, null);
nestedScrollView.dispatchNestedScroll(0, 0, 0, 0, new int[]{0, -appBarHeight});
});
This simulates scrolling halfway down.
Just using NestedScrollView.scrollTo()
is not enough to trigger the scroll events for the parent.
To create the collapsing toolbar, CollapsingToolbarLayout integrates with AppBarLayout, CoordinatorLayout, Toolbar, and a scrollable content view, such as RecyclerView