I have a long text and i want it to be displayed with a TextView. The text i have is much longer than the available space. However i don't want to use scrolling, but ViewFlipper to flip to the next page. How can i retrieve the lines from the first TextView that are not shown because the view is to short so that i can paste them into the next TextView?
Edit: I found the Solution to my Problem. I simply have to use a custom View with a StaticLayout like this:
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);
}
Thats not optimized yet but you get the point. I hope it might help somebody like me with a similar problem.