0

I am working on Book application.Let me give you all concept

There is one big text and have Multiple Textviews as per length of the Text.

I have to show one text(part of big text) which appear in the screen(No scroll).if other text not visible to the user,than other text should appear in the other textview (Next page).

as i googling , I can't find a way to take length of the text which is appear in the one textview (one page).So I can take other text in the other page

I have attached some image for clear the concepts.

enter image description here

enter image description here

Please suggest me. What can i do for that? Thank in advance

Mayur Raval
  • 3,250
  • 6
  • 34
  • 57

1 Answers1

0

ok there are three solutions

  1. if you calculate screen sizes and use sizes like small medium and large.
  2. and you just divide your data and set in textview.

Get number of lines of text that will fit on the screen than Measure how much text will fit across the TextView. Calculate Total amount of text to fill the TextView is approximately.

    private void TextMeasure(String text,
                         TextView tvl, TextView tvr) {
    int linesPerScreen = tvl.getHeight() / (tvl.getLineHeight() + (int) tvl.getLineSpacingExtra());
    Paint paint = tvl.getPaint();
    int textWidth = paint.breakText(text, 0, text.length(),
            true, tvl.getWidth(), null);
    int totalText = textWidth * linesPerScreen;
    String leftText = text.substring(0, totalText);
    String rightText = text.substring(totalText,
            text.length());
    tvl.setText(leftText);
    tvr.setText(rightText);
}

source

probably this question help you out.

Community
  • 1
  • 1
Fasiha
  • 488
  • 3
  • 11
  • Here `tvl.getLineSpacingExtra()` and `linesPerScreen` always return 0 – Mayur Raval Feb 05 '15 at 11:10
  • when you try this you find that tv.getHeight() returns 0 at this time. The reason is that the view for the activity has not been laid out yet so the TextView has no height. How to deal with this? There are several ways but the easiest is to post a Runnable to the TextView’s message queue. The Runnable will be called when after the TextView layout is complete. – Fasiha Feb 05 '15 at 12:08