Weird behaviour of ListView scrollbars
I have a ListView which I want to populate with items each of which contains only one TextView
. The thing about these TextView
-s is that they need to use custom font (not the one of three built-in fonts). I can not set custom font (typeface) via XML so 开发者_高级运维the only way to do it is call tv.setTypeface()
for all TextView-s in the getView()
method of my Adapter.
Now the problem is that the font I want to use has the pretty much different line spacing (by default) so the resulting text appears larger than the same text rendered using default font (providing we use the same textSize
for two fonts). This particulary affects the way ListView
measures the overall size (height) of my text (and thus the size of scrollbar) thinking that text is rendered using default typeface (while in reality it is not).
When I scroll my ListView
up or down the overall size of the text is constanly recalculated resulting in scrollbar changing its length (which looks weird). I wonder if there a way to tell ListView
to use my custom font before the call to getView()
method (i.e. during text measurement)?
It is default behaviour of ListView. Try to set smoothScrollbar
to true
. In XML:
android:smoothScrollbar="true"
or in code:
listView.setSmoothScrollbarEnabled(true);
It appears that the thing I am trying to achieve is impossible. Simply because there is no list item exist except for those which are visible at the moment. So the ListView does know nothing about the height of its items before they were inflated and populated with text.
What it can do - is only to make assumptions based on the item layout supplied to LIstView upon creation.
精彩评论