Calling TextView.setText() periodically causes the UI to jerk
I'm coding an audio player where a thread updates the TextView representing the track's elapsed time, every 250 milliseconds.
The display looks like this:
1:30/2:30<-----Progress Bar----->
TextView 1 is 1:30/ and TextView 2 is 2:30.
Both are set to wrap_content for width.
What happens is that on every 250 millisecond cycle, the thread checks the current time and updates TextView 1. For this brief moment, TextView 2 and the progress bar get pushed momentarily to the right by about 2-4 pixels. Then they come back to place until the same thing happens during the next cycle.
I don't know what's happening. There are no trailing space characters, etc and everything should, theoretically, be working smoothly but it's not.
Can anyon开发者_开发问答e help me out? I'm hoping someone else may have faced a similar problem....
PS: I initialize TextView 1 to 0:00/ and TextView 2 to 0:00 in the layout XML file and the code handles it from there.
Considered using a fixed width (16-20dip?) instead of wrap_content for those fields? The variable-pitched font is going to move the progress bar around, since 1:11 is narrower than, say, 1:59.
Or go to a fixed-pitch font, if the times will always be the same number of characters.
精彩评论