@@ -196,7 +196,8 @@ public class CollapsingToolbarLayout extends FrameLayout {
196
196
private int topInsetApplied = 0 ;
197
197
private boolean forceApplySystemWindowInsetTop ;
198
198
199
- private int extraMultilineHeight = 0 ;
199
+ private int extraMultilineTitleHeight = 0 ;
200
+ private int extraMultilineSubtitleHeight = 0 ;
200
201
private boolean extraMultilineHeightEnabled ;
201
202
202
203
private int extraHeightForTitles = 0 ;
@@ -307,7 +308,10 @@ public CollapsingToolbarLayout(
307
308
scrimVisibleHeightTrigger =
308
309
a .getDimensionPixelSize (R .styleable .CollapsingToolbarLayout_scrimVisibleHeightTrigger , -1 );
309
310
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 )) {
311
315
collapsingTitleHelper .setExpandedMaxLines (
312
316
a .getInt (R .styleable .CollapsingToolbarLayout_maxLines , 1 ));
313
317
}
@@ -351,6 +355,10 @@ public CollapsingToolbarLayout(
351
355
MaterialResources .getColorStateList (
352
356
context , a , R .styleable .CollapsingToolbarLayout_collapsedSubtitleTextColor ));
353
357
}
358
+ if (a .hasValue (R .styleable .CollapsingToolbarLayout_subtitleMaxLines )) {
359
+ collapsingSubtitleHelper .setExpandedMaxLines (
360
+ a .getInt (R .styleable .CollapsingToolbarLayout_subtitleMaxLines , 1 ));
361
+ }
354
362
if (a .hasValue (R .styleable .CollapsingToolbarLayout_titlePositionInterpolator )) {
355
363
collapsingSubtitleHelper .setPositionInterpolator (
356
364
android .view .animation .AnimationUtils .loadInterpolator (
@@ -690,23 +698,42 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
690
698
extraHeightForTitles = 0 ;
691
699
}
692
700
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
+ }
703
726
}
704
727
}
705
728
706
- if (extraHeightForTitles + extraMultilineHeight > 0 ) {
729
+ if (extraHeightForTitles + extraMultilineTitleHeight + extraMultilineSubtitleHeight > 0 ) {
707
730
heightMeasureSpec =
708
731
MeasureSpec .makeMeasureSpec (
709
- originalHeight + extraHeightForTitles + extraMultilineHeight , MeasureSpec .EXACTLY );
732
+ originalHeight
733
+ + extraHeightForTitles
734
+ + extraMultilineTitleHeight
735
+ + extraMultilineSubtitleHeight ,
736
+ MeasureSpec .EXACTLY );
710
737
super .onMeasure (widthMeasureSpec , heightMeasureSpec );
711
738
}
712
739
}
@@ -790,15 +817,16 @@ private void updateTextBounds(
790
817
titleBoundsRight ,
791
818
(int )
792
819
(titleBoundsBottom
793
- - collapsingSubtitleHelper .getExpandedTextFullSingleLineHeight ()
820
+ - (collapsingSubtitleHelper .getExpandedTextFullSingleLineHeight ()
821
+ + extraMultilineSubtitleHeight )
794
822
- expandedTitleSpacing ),
795
823
/* alignBaselineAtBottom= */ false );
796
824
collapsingSubtitleHelper .setExpandedBounds (
797
825
titleBoundsLeft ,
798
826
(int )
799
827
(titleBoundsTop
800
828
+ (collapsingTitleHelper .getExpandedTextFullSingleLineHeight ()
801
- + extraMultilineHeight )
829
+ + extraMultilineTitleHeight )
802
830
+ expandedTitleSpacing ),
803
831
titleBoundsRight ,
804
832
titleBoundsBottom ,
@@ -1713,6 +1741,7 @@ public void setExpandedTitleSpacing(int titleSpacing) {
1713
1741
@ RestrictTo (LIBRARY_GROUP )
1714
1742
public void setMaxLines (int maxLines ) {
1715
1743
collapsingTitleHelper .setExpandedMaxLines (maxLines );
1744
+ collapsingSubtitleHelper .setExpandedMaxLines (maxLines );
1716
1745
}
1717
1746
1718
1747
/** Gets the maximum number of lines to display in the expanded state. Experimental Feature. */
@@ -1880,7 +1909,8 @@ public int getScrimVisibleHeightTrigger() {
1880
1909
// If we have one explicitly set, return it
1881
1910
return scrimVisibleHeightTrigger
1882
1911
+ topInsetApplied
1883
- + extraMultilineHeight
1912
+ + extraMultilineTitleHeight
1913
+ + extraMultilineSubtitleHeight
1884
1914
+ extraHeightForTitles ;
1885
1915
}
1886
1916
0 commit comments