Note that there are some explanatory texts on larger screens.

plurals
  1. POBreaking large text into pages in android text switcher or view flipper
    text
    copied!<p>I am in the process of developing an e-book reader application for android 3.0 tablets. To begin with I have a large chunk of String data. I want to split/break that String into pages based on the screen size of the device [I am planning to use text switcher or view flipper]. Though I tried using getWindowManager() method I could not get the preferred results. </p> <p>In the following thread it is mentioned that Text Switcher automatically breaks the text according to the screen size. But I do not think so. <a href="https://stackoverflow.com/questions/6406882/managing-text-in-android-applicaiton-like-in-a-ebook">Managing text in android applicaiton like in a eBook</a></p> <p>This is the logic I used :</p> <pre><code> // retreiving the flipper flipper = (ViewFlipper) findViewById(R.id.new_view_flipper); // obtaining screen dimensions Display display = getWindowManager().getDefaultDisplay(); int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); // contentString is the whole string of the book while (contentString != null &amp;&amp; contentString.length() != 0) { totalPages ++; // creating new textviews for every page TextView contentTextView = new TextView(this); contentTextView.setWidth(ViewGroup.LayoutParams.FILL_PARENT); contentTextView.setHeight(ViewGroup.LayoutParams.FILL_PARENT); contentTextView.setMaxHeight(screenHeight); contentTextView.setMaxWidth(screenWidth); float textSize = contentTextView.getTextSize(); Paint paint = new Paint(); paint.setTextSize(textSize); int numChars = 0; int lineCount = 0; int maxLineCount = screenHeight/contentTextView.getLineHeight(); contentTextView.setLines(maxLineCount); while ((lineCount &lt; maxLineCount) &amp;&amp; (numChars &lt; contentString.length())) { numChars = numChars + paint.breakText(contentString.substring(numChars), true, screenWidth, null); lineCount ++; } // retrieve the String to be displayed in the current textbox String toBeDisplayed = contentString.substring(0, numChars); contentString = contentString.substring(numChars); contentTextView.setText(toBeDisplayed); flipper.addView(contentTextView); numChars = 0; lineCount = 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload