Skip to content

Commit

Permalink
[CollapsingToolbarLayout] Allow multiple lines of text in expanded state
Browse files Browse the repository at this point in the history
  • Loading branch information
johan12345 committed Jun 29, 2019
1 parent d0c397f commit 0811fba
Show file tree
Hide file tree
Showing 3 changed files with 299 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ public CollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyle
a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance, 0));
}

if (a.hasValue(R.styleable.CollapsingToolbarLayout_maxLines)) {
collapsingTextHelper.setMaxLines(a.getInt(R.styleable.CollapsingToolbarLayout_maxLines, 1));
}

if (a.hasValue(R.styleable.CollapsingToolbarLayout_lineSpacingExtra)) {
collapsingTextHelper.setLineSpacingExtra(
a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_lineSpacingExtra, 0));
}

if (a.hasValue(R.styleable.CollapsingToolbarLayout_lineSpacingMultiplier)) {
collapsingTextHelper.setLineSpacingMultiplier(
a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_lineSpacingMultiplier, 1));
}

scrimVisibleHeightTrigger =
a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_scrimVisibleHeightTrigger, -1);

Expand Down Expand Up @@ -1027,6 +1041,48 @@ public void setExpandedTitleMarginBottom(int margin) {
requestLayout();
}

/**
* Sets the maximum number of lines to display in the expanded state.
*/
public void setMaxLines(int maxLines) {
collapsingTextHelper.setMaxLines(maxLines);
}

/**
* Gets the maximum number of lines to display in the expanded state.
*/
public int getMaxLines() {
return collapsingTextHelper.getMaxLines();
}

/**
* Set line spacing extra applied to each line in the expanded state.
*/
void setLineSpacingExtra(float lineSpacingExtra) {
collapsingTextHelper.setLineSpacingExtra(lineSpacingExtra);
}

/**
* Gets the line spacing extra applied to each line in the expanded state.
*/
float getLineSpacingExtra() {
return collapsingTextHelper.getLineSpacingExtra();
}

/**
* Sets the line spacing multiplier applied to each line in the expanded state.
*/
void setLineSpacingMultiplier(float lineSpacingMultiplier) {
collapsingTextHelper.setLineSpacingMultiplier(lineSpacingMultiplier);
}

/**
* Gets the line spacing multiplier applied to each line in the expanded state.
*/
float getLineSpacingMultiplier() {
return collapsingTextHelper.getLineSpacingMultiplier();
}

/**
* Set the amount of visible height in pixels used to define when to trigger a scrim visibility
* change.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@
<attr name="titleEnabled" format="boolean"/>
<!-- The title to show when titleEnabled is set to true. -->
<attr name="title"/>
<!-- The maximum number of lines of text to show in the expanded state -->
<attr name="maxLines" format="integer" />
<!-- Extra spacing between lines of text. -->
<attr name="lineSpacingExtra" format="float"/>
<!-- Extra spacing between lines of text, as a multiplier. -->
<attr name="lineSpacingMultiplier" format="float"/>
</declare-styleable>

<declare-styleable name="CollapsingToolbarLayout_Layout">
Expand Down
Loading

0 comments on commit 0811fba

Please sign in to comment.