If the text in the TextView is larger than the available space, how do I get the remaining lines?

I have a long text and I want it to be displayed using a TextView. The text that I have is much longer than the free space. However, I do not want to use scrolling, but ViewFlipper switches to the next page. How can I get lines from the first TextView that are not displayed because the view is short so that I can insert them into the next TextView?

Edit: I found a solution to my problem. I just need to use a custom view with StaticLayout as follows:

public ReaderColumView(Context context, Typeface typeface, String cText) {
        super(context);
        Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        dWidth = display.getWidth(); 
        dHeight = display.getHeight();

        contentText = cText;

        tp = new TextPaint();
        tp.setTypeface(typeface);
        tp.setTextSize(25);
        tp.setColor(Color.BLACK);
        tp.setAntiAlias(true);

        StaticLayout measureLayout = new StaticLayout(contentText, tp, 440, Alignment.ALIGN_NORMAL, 1, 2, true);
        Boolean reachedEndOfScreen = false;
        int line = 0;
        while (!reachedEndOfScreen) {
            if (measureLayout.getLineBottom(line) > dHeight-30) {
            reachedEndOfScreen = true;
            fittedText = contentText.substring(0, measureLayout.getLineEnd(line-1));
            setLeftoverText(contentText.substring(measureLayout.getLineEnd(line-1)));
            }

            line++;

        }
    }
protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        StaticLayout textLayout = new  StaticLayout(fittedText, tp, 440, Alignment.ALIGN_NORMAL, 1, 2, true);
        canvas.translate(20,20);
        textLayout.draw(canvas);
    }

This is not yet optimized, but you understand. I hope this can help someone like me with a similar problem.

+5
1

, StaticLayout . ,

  • StaticLayout onDraw, , . onMeasure .
  • while, (while (! reachEndOfScreen)), StaticLayout.getLineForVertical(int offset).
  • leftOverText StaticLayout .
0

All Articles