Questions tagged [staticlayout]

An Android text layout class for laying out text that will not change.

The Android documentation is here.

If the text will change then a DynamicLayout is used.

39 questions
32
votes
2 answers

How is StaticLayout used in Android?

I need to build my own custom TextView so I have been learning about StaticLayout to draw text on a canvas. This is preferable to using Canvas.drawText() directly, or so the documentation says. However, the documentation doesn't give any examples…
Suragch
  • 364,799
  • 232
  • 1,155
  • 1,198
20
votes
1 answer

What is Leading Margin in Android?

What is the meaning of leading margin as in LeadingMarginSpan LeadingMarginSpan.Standard LeadingMarginSpan.LeadingMarginSpan2 The documentation for LeadingMarginSpan says A paragraph style affecting the leading margin. There can be multiple …
Suragch
  • 364,799
  • 232
  • 1,155
  • 1,198
9
votes
1 answer

What is the substitute for deprecated StaticLayout

What should be used instead of: StaticLayout layout = new StaticLayout(text, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, false); Gives this warning: warning: [deprecation] …
MiguelSlv
  • 9,553
  • 7
  • 72
  • 127
8
votes
2 answers

How to fit text into StaticLayout with fixed width and height in Android?

I'm trying to draw text using Canvas and have found that using StaticLayout would take care of the line breaks automatically. I also want to limit its height so that when text is too long it would be ellipsized, but the size of text container is…
user1865027
  • 2,915
  • 4
  • 26
  • 56
5
votes
1 answer

TextRendering in TextView and EditText

I have a simple layout like this:
Hojjat
  • 755
  • 1
  • 9
  • 23
5
votes
1 answer

Android Text Layout Spacingmult and Spacingadd?

public 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) In the…
NamHo Lee
  • 269
  • 2
  • 11
4
votes
2 answers

How to set "Text direction" to RTL in StaticView

I am using a StaticLayout and using some RTL text. The problem is that it's not handling RTL well. In TextView you can set a "textDirection". is there any way to do it here too? Thanks!
roiberg
  • 12,799
  • 11
  • 54
  • 87
3
votes
1 answer

Android: How to restrict upto two line in static layout on image

I have one image and on that i have to write top and bottom text, i am using static layout to write on it. Below is the code of it TextPaint mTextPaintTop= new TextPaint(); mTextPaintTop.setColor(Color.RED); StaticLayout layoutTop = new…
moDev
  • 5,163
  • 4
  • 31
  • 63
3
votes
0 answers

StaticLayout render wrongly with Android Nougat

I render text via StaticLayout and draw it in onDraw() in my custom view, not TextView. Everything works fine until I test my application with Android Nougat. In some cases, StaticLayout is created wrongly with lineWidth bigger than the outerWidth…
Huy Duong Tu
  • 7,238
  • 5
  • 22
  • 45
2
votes
1 answer

StaticLayout height is less than TextView's true height

I use StaticLayout to handle my text, then showed in TextView.But when i call getHeight of StaticLayout to get handled text height, it is less than the textview's true height. below is core code: private fun createStaticLayout(text:…
Alan W.
  • 3,921
  • 2
  • 13
  • 22
2
votes
1 answer

How to reduce StaticLayout delay when using long text

I use StaticLayout to paginate my text to create an epub application, and I have a text that has 16,000 lines. The StaticLayout object is created about 6 seconds later and it's very slow. How can I reduce this time or is there another way to use…
2
votes
1 answer

Drawing StaticLayout not working correct

I've implemented a View with a Text.Layout and I'm drawing it but I'm getting nothing. Here is my code public class MyEfficientTextView extends View { Layout textLayout; SpannableStringBuilder spannableStringBuilder; int width = 0,…
Amir_P
  • 5,418
  • 2
  • 33
  • 74
2
votes
1 answer

How LineSpace Affects StaticLayout Height in One Line Text

Consider this simple example: I have a single line text like this: "Hello" I wanna measure this text using StaticLayout. So I wrote something like this: StaticLayout layout = new StaticLayout("Hello", myTextView.getPaint(), myTextView.getWidth(),…
Hojjat
  • 755
  • 1
  • 9
  • 23
2
votes
1 answer

Why does calling StaticLayout.Builder throw the exception java.lang.NoClassDefFoundError?

Android M has changed the setters for StaticLayout and instead we have the Builder pattern. But with the following code: StaticLayout staticLayout = StaticLayout.Builder.obtain("Hello", 0, "Hello".length(), getTextPaint(), 100).build(); I get the…
stefdev777
  • 391
  • 4
  • 15
1
vote
0 answers

How to get bound of StaticLayout drawn on canvas that fit its content?

I have a StaticLayout which contains some texts, the layout is drawn on canvas with translation, scale and rotation. I want to get the bound of this StaticLayout no matter how rotation level is. If I save the bound of the layout with left, top,…
Nam Nô
  • 11
  • 3
1
2 3