What is the display parameter in DynamicLayout

187 Views Asked by At

The DynamicLayout constructor has a base parameter and a display parameter, both of which are CharSequence. (StaticLayout, by comparison, lacks this.)

DynamicLayout (CharSequence base, 
                CharSequence display, 
                TextPaint paint, 
                int width, 
                Layout.Alignment align, 
                float spacingmult, 
                float spacingadd, 
                boolean includepad, 
                TextUtils.TruncateAt ellipsize, 
                int ellipsizedWidth)

What does the display parameter mean? The documentation says nothing. I looked into the source code and I see both an mBase and an mDisplay but I can't figure out the difference between them. My best guess is that display has something to do with ellipsized text, though why one would need to pass in two different character sequences is beyond me.

The most basic constructor lacks the display parameter (it is set equal to base in the source code), so I assume display provides some sort of optional functionality. What is it?

1

There are 1 best solutions below

0
On BEST ANSWER

TextView uses it with different arguments when there's a TransformationMethod attached, such as in the case of <EditText android:password="true"/>.

DynamicLayout attaches a change listener to the base text, but otherwise performs all the layout on the transformed text. Thus, when the base text is edited, it will be notified, and will update the layout on the affected range in the transformed text.

When base = display, it's watching for changes and computing layout on the same CharSequence. Which is the expected behavior for non-transformed text.