@@ -196,7 +196,8 @@ public class CollapsingToolbarLayout extends FrameLayout {
196196 private int topInsetApplied = 0 ;
197197 private boolean forceApplySystemWindowInsetTop ;
198198
199- private int extraMultilineHeight = 0 ;
199+ private int extraMultilineTitleHeight = 0 ;
200+ private int extraMultilineSubtitleHeight = 0 ;
200201 private boolean extraMultilineHeightEnabled ;
201202
202203 private int extraHeightForTitles = 0 ;
@@ -307,7 +308,10 @@ public CollapsingToolbarLayout(
307308 scrimVisibleHeightTrigger =
308309 a .getDimensionPixelSize (R .styleable .CollapsingToolbarLayout_scrimVisibleHeightTrigger , -1 );
309310
310- if (a .hasValue (R .styleable .CollapsingToolbarLayout_maxLines )) {
311+ if (a .hasValue (R .styleable .CollapsingToolbarLayout_titleMaxLines )) {
312+ collapsingTitleHelper .setExpandedMaxLines (
313+ a .getInt (R .styleable .CollapsingToolbarLayout_titleMaxLines , 1 ));
314+ } else if (a .hasValue (R .styleable .CollapsingToolbarLayout_maxLines )) {
311315 collapsingTitleHelper .setExpandedMaxLines (
312316 a .getInt (R .styleable .CollapsingToolbarLayout_maxLines , 1 ));
313317 }
@@ -351,6 +355,10 @@ public CollapsingToolbarLayout(
351355 MaterialResources .getColorStateList (
352356 context , a , R .styleable .CollapsingToolbarLayout_collapsedSubtitleTextColor ));
353357 }
358+ if (a .hasValue (R .styleable .CollapsingToolbarLayout_subtitleMaxLines )) {
359+ collapsingSubtitleHelper .setExpandedMaxLines (
360+ a .getInt (R .styleable .CollapsingToolbarLayout_subtitleMaxLines , 1 ));
361+ }
354362 if (a .hasValue (R .styleable .CollapsingToolbarLayout_titlePositionInterpolator )) {
355363 collapsingSubtitleHelper .setPositionInterpolator (
356364 android .view .animation .AnimationUtils .loadInterpolator (
@@ -690,23 +698,42 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
690698 extraHeightForTitles = 0 ;
691699 }
692700
693- // Calculates the extra height needed for the multiline title, if needed.
694- if (extraMultilineHeightEnabled && collapsingTitleHelper .getExpandedMaxLines () > 1 ) {
695- int lineCount = collapsingTitleHelper .getExpandedLineCount ();
696- if (lineCount > 1 ) {
697- // Add extra height based on the amount of height beyond the first line of title text.
698- int expandedTextHeight =
699- Math .round (collapsingTitleHelper .getExpandedTextFullSingleLineHeight ());
700- extraMultilineHeight = expandedTextHeight * (lineCount - 1 );
701- } else {
702- extraMultilineHeight = 0 ;
701+ if (extraMultilineHeightEnabled ) {
702+ // Calculates the extra height needed for the multiline title, if needed.
703+ if (collapsingTitleHelper .getExpandedMaxLines () > 1 ) {
704+ int lineCount = collapsingTitleHelper .getExpandedLineCount ();
705+ if (lineCount > 1 ) {
706+ // Add extra height based on the amount of height beyond the first line of title text.
707+ int expandedTextHeight =
708+ Math .round (collapsingTitleHelper .getExpandedTextFullSingleLineHeight ());
709+ extraMultilineTitleHeight = expandedTextHeight * (lineCount - 1 );
710+ } else {
711+ extraMultilineTitleHeight = 0 ;
712+ }
713+ }
714+ // Calculates the extra height needed for the multiline subtitle, if needed.
715+ if (collapsingSubtitleHelper .getExpandedMaxLines () > 1 ) {
716+ int lineCount = collapsingSubtitleHelper .getExpandedLineCount ();
717+ if (lineCount > 1 ) {
718+ // Add extra height based on the amount of height beyond the first line of subtitle
719+ // text.
720+ int expandedTextHeight =
721+ Math .round (collapsingSubtitleHelper .getExpandedTextFullSingleLineHeight ());
722+ extraMultilineSubtitleHeight = expandedTextHeight * (lineCount - 1 );
723+ } else {
724+ extraMultilineSubtitleHeight = 0 ;
725+ }
703726 }
704727 }
705728
706- if (extraHeightForTitles + extraMultilineHeight > 0 ) {
729+ if (extraHeightForTitles + extraMultilineTitleHeight + extraMultilineSubtitleHeight > 0 ) {
707730 heightMeasureSpec =
708731 MeasureSpec .makeMeasureSpec (
709- originalHeight + extraHeightForTitles + extraMultilineHeight , MeasureSpec .EXACTLY );
732+ originalHeight
733+ + extraHeightForTitles
734+ + extraMultilineTitleHeight
735+ + extraMultilineSubtitleHeight ,
736+ MeasureSpec .EXACTLY );
710737 super .onMeasure (widthMeasureSpec , heightMeasureSpec );
711738 }
712739 }
@@ -790,15 +817,16 @@ private void updateTextBounds(
790817 titleBoundsRight ,
791818 (int )
792819 (titleBoundsBottom
793- - collapsingSubtitleHelper .getExpandedTextFullSingleLineHeight ()
820+ - (collapsingSubtitleHelper .getExpandedTextFullSingleLineHeight ()
821+ + extraMultilineSubtitleHeight )
794822 - expandedTitleSpacing ),
795823 /* alignBaselineAtBottom= */ false );
796824 collapsingSubtitleHelper .setExpandedBounds (
797825 titleBoundsLeft ,
798826 (int )
799827 (titleBoundsTop
800828 + (collapsingTitleHelper .getExpandedTextFullSingleLineHeight ()
801- + extraMultilineHeight )
829+ + extraMultilineTitleHeight )
802830 + expandedTitleSpacing ),
803831 titleBoundsRight ,
804832 titleBoundsBottom ,
@@ -1713,6 +1741,7 @@ public void setExpandedTitleSpacing(int titleSpacing) {
17131741 @ RestrictTo (LIBRARY_GROUP )
17141742 public void setMaxLines (int maxLines ) {
17151743 collapsingTitleHelper .setExpandedMaxLines (maxLines );
1744+ collapsingSubtitleHelper .setExpandedMaxLines (maxLines );
17161745 }
17171746
17181747 /** Gets the maximum number of lines to display in the expanded state. Experimental Feature. */
@@ -1880,7 +1909,8 @@ public int getScrimVisibleHeightTrigger() {
18801909 // If we have one explicitly set, return it
18811910 return scrimVisibleHeightTrigger
18821911 + topInsetApplied
1883- + extraMultilineHeight
1912+ + extraMultilineTitleHeight
1913+ + extraMultilineSubtitleHeight
18841914 + extraHeightForTitles ;
18851915 }
18861916
0 commit comments