Google currents like page reading style

I’m learning how to implement a one-page reading style, for example, in Google Currents, for my application.

The content (text) is customizable depending on the size of the screen, and there is no scrolling, no scaling. Crowded text is on the next page. (I knew he was using ViewPager.)

Here are the screens: First pagesecond-page with overflowed text

My questions:

  • How can I put (customize) the content (text) on the screen?
  • How can I automatically parse overflowing text to the next screen? (so that the user will need to scroll between screens to read.)

In addition, I am considering using TextView for content. (GoogleCurrent used WebView, I think) My application does not need to use WebView. Would it be possible for the textual representation to be so?

+4
source share
1 answer

I implemented something similar with multiple TextViews. First of all, I created a ViewPager for swyping between TextViews. After that, I select the long text for several blocks, one per page. To get the text for the page, I use this function:

TextView tv = new TextView(context); //creating text view int width = mtv.getWidth() - tv.getPaddingLeft()-tv.getPaddingRight(); //get width for text int lHeight = tv.getLineHeight(); getting line height int height = ((View)mtv.getParent()).getHeight() - tv.getPaddingBottom()-tv.getPaddingTop(); // getting height of text int linesCount = (int)Math.floor((float)height/lHeight); // get line count on page String tmpText = ""; for (int i =0; i<linesCount; i++) { int index = Math.min(mtv.getLayout().getPaint().breakText(text, true, width, new float[0]), text.indexOf('\n')+1); // breaking text to lines. To use this you need mtv to be measured String t = text.substring(0, index); //getting text for this textview if (index+1 < text.length() && (text.charAt(index+1)!=' ' || text.charAt(index+1)!='\n') && t.lastIndexOf(" ")>0) index = t.lastIndexOf(" ")+1; // hack for situation when line starts with " " text = text.substring(index);//getting text for next iteration t = t.substring(0, index); tmpText+=t; } //I use spannable string for links and some styles. Recalculating spans for new indexes SpannableString s = new SpannableString(tmpText); Object os[] = spanned.getSpans(offset, offset + tmpText.length(), Object.class); for (Object o: os) { int start = spanned.getSpanStart(o)-offset; int end = spanned.getSpanEnd(o)-offset; if (start < 0) start = 0; if (end>=s.length()) end = s.length()-1; s.setSpan(o, start, end, spanned.getSpanFlags(o)); } offset+=tmpText.length(); while (text.startsWith(" ") || text.startsWith("\n")) { text = text.substring(1); offset++; } tv.setText(s); 

Above, I think Google uses a TextView, not a webView. Read about Spanned and Spannable. It has the ability to display links, images, text with different styles in one text file.

+3
source

All Articles