0

I am trying to build something like a text reader. It must have a horizontal slide (normal book-ish), not scroll down.

To accomplish that I am dynamically filling a ViewFlipper with many TextViews. Intuitive idea is that I create a new TextView on each previous TextView overflow, and add it to a ViewFlipper.

I might accomplish that with setMaxLines(), but I can`t get the text that goes beyond that max line.

Question:

How can I move text from one TextView to another on overflow?

or

Am I fundamentally wrong with method I decided to use?

EDIT:

Sorry, I cant make my problem clear for some reason. Maybe this will help:

TextView text1, text2;
String s = "Extreamly long string. Much longer than this one";
text1.setText(s);
text2.setText( // Text that is overflowing //);

How do I figure out what part of the String is visible, and what part is overflowing?

Thanks

igorshkov
  • 3
  • 4

1 Answers1

0
    TextView tv = new TextView(context);

    ViewTreeObserver vto = tv.getViewTreeObserver();

    vto.addOnGlobalLayoutListener(

            new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {

                    Layout l = tv.getLayout();

                    int height = tv.getHeight();
                    int scrollY = tv.getScrollY();

                    /**
                     * Key part
                     */

                    int lineCount = l.getLineForVertical(height + scrollY);

                    int start = l.getLineStart(0);
                    int end = l.getLineEnd(lineCount - 1);

                    /**
                     * Cut string
                     */

                    String s = tv.getText().toString().substring(start, end);

                }

            }
    );
igorshkov
  • 3
  • 4