I'm trying to split some text across multiple Fragments loaded into a ViewPager using the Android compatibility library. The idea is to have something akin to the Kindle app, where you are swiping across multiple pages of text.
Initially, my source of text is a string defined in strings.xml and I am using an algorithm to determine the height of the device screen, and then split this string accordingly into a number of items for the ViewPager. As you can't get the height of a TextView ahead of time, I am just using a percentage value to determine what to set the maximum size of the TextView to on each page (this seems a bit ugly).
Does this seem like a reasonable approach, or am I going about this all the wrong way?
As you can't get the height of a TextView ahead of time
Well, that depends on what you mean by "ahead of time" (time == text processing?).
measure()
your ViewPager
/TextView
once and use its getMeasuredHeight()/getMeasuredWidth()
in your calculations ViewTreeObserver.OnGlobalLayoutListener.onGlobalLayout()
and use the "standard" layout measurements for the very same thingIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With