I have long data that I want to see in TextView. I am trying to work on pagination with the following code:
TextPaint textPaint = tv.getPaint();
int boundedWidth = tv.getWidth();
StaticLayout layout = new StaticLayout(data, textPaint, boundedWidth , Alignment.ALIGN_NORMAL, 1.0f, 1, false);
layout.draw(new Canvas());
int totalLines = layout.getLineCount();
int currentPageNum = 0;
int topLine = 0;
int bottomLine = 0;
topLine = layout.getLineForVertical( currentPageNum * height );
bottomLine = layout.getLineForVertical( (currentPageNum + 1) * height );
int pageOffset = layout.getLineStart(topLine);
int pageEnd = layout.getLineEnd(bottomLine);
tv.setText(data.subSequence(pageOffset, pageEnd));
But pageoffset and pageend give me startline+1 and endline+1 value not exact offset of text which should be drawn.
What is wrong with my code? Is there any other way ?
Finally i have make it work. My boundedWidth was zero so that why it was returning false data.