staticlayout

How to reduce StaticLayout delay when using long text

给你一囗甜甜゛ 提交于 2020-06-23 03:32:39
问题 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 StaticLayout instead? 回答1: The problem is that you're trying to lay out the whole thing at once. Laying out 16,000 lines of text is expensive . It's going to take a nontrivial amount of time even on a desktop computer with a powerful CPU, and you're

ImageSpan Size Measurement with TextView and StaticLayout

北战南征 提交于 2020-01-07 06:24:34
问题 I have a simple layout contains just one TextView . I wanna load an image into TextView using ImageSpan. Below method creates Spannable : private Spannable getImageSpannable(int drawableId, int targetWidth, int targetHeight) { Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), drawableId); Bitmap bitmap = Bitmap.createScaledBitmap(originalBitmap, targetWidth, targetHeight, true); Drawable dr = new BitmapDrawable(getResources(), bitmap); dr.setBounds(0, 0, bitmap.getWidth(),

How LineSpace Affects StaticLayout Height in One Line Text

我是研究僧i 提交于 2020-01-04 09:17:55
问题 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(), Layout.Alignment.NORMAL, 1, lineSpace, false); In above code I changed lineSpace variable in a for loop and every time log the layout's height: for(int lineSpace=0; lineSpace<20;lineSpace++){ StaticLayout layout = new StaticLayout("Hello", myTextView

StaticLayout too much time taking

十年热恋 提交于 2019-12-23 05:05:08
问题 I use StaticLayout to Paginate my Html Text. But when I use large text in StaticLayout Constructing process is very heavy and taking a lot of time. It's Just Happen in androids below android 5 How can I resolve this problem? this is my code public class PageSplitter { private final int pageWidth; private final int pageHeight; private final float lineSpacingMultiplier; private final float lineSpacingExtra; private final List<CharSequence> pages = new ArrayList<CharSequence>(); private

How is StaticLayout used in Android?

十年热恋 提交于 2019-12-17 04:50:18
问题 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 for how do it. There is only a vague reference to StaticLayout.Builder being the newer way to do it. I found an example here but it seems a little dated. I finally worked though how to do it so I am adding my explanation below. 回答1: StaticLayout

How TextSize and LineSpace affects ImageSpan

守給你的承諾、 提交于 2019-12-11 06:25:38
问题 I want to measure ImageSpan with StaticLayout. to do this I use a simple code like below: SpannableStringBuilder content = new SpannableStringBuilder(); Spannable imageSpannable = getImageSpannable(); content.append(imageSpannable); StaticLayout layout = new StaticLayout(content, txt.getPaint(), txt.getWidth(), Layout.Alignment.ALIGN_NORMAL, 1, lineSpace, false); txt is a TextView and lineSpace just a variable indicating txt line space. And getImageSpannable: private Spannable

What is the substitute for deprecated StaticLayout

别说谁变了你拦得住时间么 提交于 2019-12-07 05:59:35
问题 What should be used instead of: StaticLayout layout = new StaticLayout(text, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, false); Gives this warning: warning: [deprecation] StaticLayout(CharSequence,TextPaint,int,Alignment,float,float,boolean) in StaticLayout has been deprecated StaticLayout layout = new StaticLayout(text, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, false); 回答1: Use StaticLayout.Builder . Go through here for more details: https:/

What is the substitute for deprecated StaticLayout

百般思念 提交于 2019-12-05 08:52:22
What should be used instead of: StaticLayout layout = new StaticLayout(text, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, false); Gives this warning: warning: [deprecation] StaticLayout(CharSequence,TextPaint,int,Alignment,float,float,boolean) in StaticLayout has been deprecated StaticLayout layout = new StaticLayout(text, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, false); S.M Use StaticLayout.Builder . Go through here for more details: https://developer.android.com/reference/android/text/StaticLayout.Builder for your case use: StaticLayout.Builder sb

How is StaticLayout used in Android?

风格不统一 提交于 2019-11-26 21:59:41
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 for how do it. There is only a vague reference to StaticLayout.Builder being the newer way to do it. I found an example here but it seems a little dated. I finally worked though how to do it so I am adding my explanation below. Suragch StaticLayout ( similar to DynamicLayout and BoringLayout ) is used to layout and draw text on a canvas. It is