opacapp / multiline-collapsingtoolbar

A modified CollapsingToolbarLayout that can deal with multiline titles
Other
782 stars 113 forks source link

New line without the need #50

Closed Angels-group closed 6 years ago

Angels-group commented 6 years ago

Thank you very much for the library! I have a question - why is a new line created in Title (the third)? Visually, the header could fit into 2 lines. screenshot_2

My xml insert: <net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimaryDark" app:expandedTitleGravity="bottom" app:expandedTitleMarginBottom="0dp" app:expandedTitleMarginStart="16dp" app:expandedTitleTextAppearance="@style/collapsingTitle" app:maxLines="3" app:expandedTitleMarginEnd="0dp" app:layout_scrollFlags="scroll|exitUntilCollapsed">

johan12345 commented 6 years ago

How does this look like in the collapsed state? I suspect that the reason for the third line is that with only two lines, the second line would be longer than the (proportionally scaled) space that is available for the first line in the collapsed state.

Angels-group commented 6 years ago

screenshot_3

Is there no way to do the first line of width to move to the Toolbar, and the remaining lines do more (like match_parent)?

johan12345 commented 6 years ago

Well, that would probably be quite difficult, as Android's text layout classes are only designed for text in a rectangular frame, not with different widths for each line. Also it would probably look quite strange when the first line is shorter than the other ones.

Another possibility would be to make all lines (including the first one) match the width of the toolbar, but that would mean that during the transition between collapsed and expanded state, part of the text would appear behind the toolbar buttons, which also doesn't look great.

johan12345 commented 6 years ago

Hmmm, it might also be that this is related to #26 and therefore might get fixed by #46 .

Angels-group commented 6 years ago

I have some idea - may be it is possible to use two textLayouts (StaticLayout mTextLayout1 and StaticLayout mTextLayout2). First, the given title (mText) is measured and divided into 2 parts. mTextLayout1 - has a length that can fit to toolbar in a collapsed state (red is screenshot) mTextLayout2 - all that is left and what will be hidden and what you can see in expanded state (green in screenshot)

scr_toolbar

I do not fully understand how this library works, so my guesswork may not be true. I apologize in advance.