Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add ellipses to text StaticLayout when it exceeds its height?

I'm programmatically creating StaticLayouts with varying strings, and then applying each to a bitmap that is then added to a canvas. The SL displays up to two lines before getting cut off by the fixed height that I defined in the SL constructor. But there is no ellipses to indicate that the text is longer than what is shown.

From http://developer.android.com/reference/android/text/StaticLayout.html I see that the third constructor has truncation arguments at the end:

StaticLayout(CharSequence source, int bufstart, int bufend, TextPaint paint, int outerwidth, Layout.Alignment align, float spacingmult, float spacingadd, boolean includepad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth)

I know I'd like TextUtils.TruncateAt.END, but I can't figure out what I should be defining for bufstart, bufend, and ellipsizedWidth. I couldn't find any good examples of this constructor in particular, or if it will even help achieve my goal.

like image 484
annie Avatar asked Jun 08 '12 01:06

annie


1 Answers

Not 100% familiar with Android, but have had the same issue myself and this is what I've found:

  • bufstart - index of the first character (in source) to include in the layout
  • bufend - index of the last character to include in the layout
  • outerwidth - I think the width of the imaginary box containing all your text (I've just made it really really wide)
  • ellipsizedwidth - the width of your box your drawing into, text will be trimmed if it exceeds this

Sorry for a not-so-confident answer, but I'm still learning!

like image 198
Jake R Avatar answered Nov 16 '22 00:11

Jake R