Android viewpager contains long text divided into pages

I have it viewPager

in my application. I want to fit a long block of text into viewPager

. I don't want the text to be scrollable, I want it to be split or split into pages, and when custom pages display the rest of the text on other pages.

How can I approach this?

+1


source to share


2 answers


You can create multiple slices based on the dimension of the text measured with public float measureText (String text)

. Then you define the screen as mentioned in Get screen dimensions in pixels

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

      



And this way you can calculate the number of fragments you need.
For the splitting part, the fastest solution I can think of would be to loop with measureText (String text, int start, int end)

to determine where the text should be split. (There may be more elegant solutions out there)

0


source


Using the (Boring | Static | Dynamic) Layout classes to measure and wrap text, the Theses class takes width as a constructor parameter and calculates the overall height of your text, and also provides methods like getLineHeight (int line) to get the info string, so you can calculate the line offset according to this data. I am creating a class for this, see my answer here: fooobar.com/questions/2224506 / ...



0


source







All Articles