Android ListView fast scroll with sections: section text too long
Asked Answered
G

1

10

I am using ListView to implement a timeline. I enabled FastScroll and used SectionIndexer so that user could drag the scrollbar and see the section text displayed.

The problem is all these are built-in UI. The textview that displays the section text is too small for me, I am trying to display 05pm and it's too long for the textview(or other UI?).

Any easier way to resolve this? For instance, a method I can set the font size of the section text or the textview layout?

Thanks!

Movie Timeline with FastScroll enabled

Gyatt answered 26/10, 2012 at 19:22 Comment(4)
Same problem here. All I can find is a custom fast scroll implementation which displays a toast message. Surely there must be a way to reduce the font size.Tewell
offtopic, but what font are you using for the bold font? ontopic: I'm not an expert, but I'm guessing that the fastscroller is a view, so there has to be a way to inflate it, then modify the textview in it.Garlan
@EvanR. "what font are you using for the bold font?" It's just regular font with black. bold and large size.Gyatt
@Tewell "Surely there must be a way to reduce the font size." --Have you find a way to reduce the font size yet?Gyatt
L
1

Looking through the source code for AbsListView, you can find the class that handles the fast scrolling mechanism which ends up being FastScroller. FastScroller actually draws the image drawable and text on the canvas that was provided to the AbsListView like so...

canvas.drawText(mSectionText, (int) (rectF.left + rectF.right) / 2 - hOff, (int) (rectF.bottom + rectF.top) / 2 + mOverlaySize / 4 - descent - vOff, paint);

The code above actually draws the text on top of the bottom image drawable so it does not respect the bounds of the bottom drawable, which is why the text is actually overflowing and not being cut off. As to why this is designed this way? My guess is that the intention of the index feature was to be mainly used for single characters such as A, B, C, etc... and therefore the fast scroll index feature was designed to fit that.

So, to give a definite answer to your question, there's really no way to change the text size or change how the text is being drawn unless you modify AbsListView and FastScroller to suit your need.

Lacreshalacrimal answered 5/4, 2013 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.