I have some text in a file [~100 KB
] that needs to be displayed to the user in a TextView
. I want to split the text into pages.
This is the idea I have in mind to implement pagination:
- Determine screen width and screen height, say
320 x 480
. - Calculate 75% of height, [360
px
] to accommodate buttons etc. - Determine font size
- Calculate number of characters [
N
] that can be displayed. - Read from file and display only
N
number of characters.
This seems like it would work, but it seems crude and error-prone. Does anyone have better ideas?
You should create your own extension of TextView and hook up into the onMeasure function which should give you the width and height (prob want to give the textview layout_weight=1)
Then you can use a paint to get the size that text will take up, not I've not tested this and you'll probably need to do something to account for splitting of newlines. But it is a good start...