From 7f556038b00b9cee9efe290ce79c2f99071463cd Mon Sep 17 00:00:00 2001 From: Marten Gajda Date: Fri, 7 Apr 2017 14:24:19 +0200 Subject: [PATCH] Add "autoAnimate" attribute to configure how scrim and title behave when collapsing the toolbar. none - nothing will be auto-animated, i.e. values change gradually as you scroll title - the title blending will be auto-animated when the scrim height has been reached scrim - scrim will be auto-animated when the scrim height has been reached (this is the default) all - title and scrim will be auto-animated when the scrim height as been reached Note there is another value "children" which requires the changes of another branch to work --- demo/src/main/res/layout/activity_demo.xml | 5 +++ .../CollapsingTextHelper.java | 40 +++++++++++++---- .../CollapsingToolbarLayout.java | 45 ++++++++++++++++--- .../res/values/collapsing_toolbar_attrs.xml | 7 +++ 4 files changed, 81 insertions(+), 16 deletions(-) diff --git a/demo/src/main/res/layout/activity_demo.xml b/demo/src/main/res/layout/activity_demo.xml index ab78bfd..249095e 100644 --- a/demo/src/main/res/layout/activity_demo.xml +++ b/demo/src/main/res/layout/activity_demo.xml @@ -21,8 +21,13 @@ app:layout_scrollFlags="scroll|exitUntilCollapsed" app:title="@string/title" app:expandedTitleTextAppearance="@style/TextAppearance.ExpandedTitle" + app:autoAnimate="all" + app:contentScrim="#ff00ff" app:maxLines="3"> + 0) { ViewCompat.postInvalidateOnAnimation(CollapsingToolbarLayout.this); } // Update the collapsing text's fraction - final int expandRange = getHeight() - ViewCompat.getMinimumHeight( - CollapsingToolbarLayout.this) - insetTop; - mCollapsingTextHelper.setExpansionFraction( - Math.abs(verticalOffset) / (float) expandRange); + mCollapsingTextHelper.setExpansionFraction(expandRatio); + + if ((mAutoAnimate & AUTO_ANIMATE_TITLE) == 0) { + // title blend it not auto-animated + mCollapsingTextHelper.setBlendRatio(expandRatio); + } + // END MODIFICATION } } } diff --git a/multiline-collapsingtoolbar/src/main/res/values/collapsing_toolbar_attrs.xml b/multiline-collapsingtoolbar/src/main/res/values/collapsing_toolbar_attrs.xml index 823cd33..5632163 100644 --- a/multiline-collapsingtoolbar/src/main/res/values/collapsing_toolbar_attrs.xml +++ b/multiline-collapsingtoolbar/src/main/res/values/collapsing_toolbar_attrs.xml @@ -3,6 +3,13 @@ + + + + + + + \ No newline at end of file