MfA tricks #11 - Adding ListView items with panache
ListView is probably the most fundamental UI component of Android and I bet you can hardly find an app which doesn’t use one in a form or another.
ListView doesn’t offer much eye candy, it’s basically a scrollable vertical
LinearLayout with glowing overscrolls.
But fortunately since
ListView can be directly feeded
View instances with a custom
BaseAdapter, nothing prevents us from spraying some animation on top of them.
Since the data displayed in a
ListView is generally queried from some distant network services, there is an opportunity for a visual feedback to inform the user of a freshly retrieved element.
If you have used the Google+ Android application, you are probably familiar with this as new items in your feed are added with a one-time slide-in animation to make it look like they are appended live to your stream.
The good news is that this effect is proposed by default in the Android framework with the
AnimationUtils class (in
This class contains the
MakeInChildBottomAnimation method that will automatically craft an
Animation instance for you reproducing that slide in effect.
The only thing left to do is to plug in that method invocation in your adapter
GetView method like so:
Result (a bit jerky thanks to the emulator):
On a final note, I have observed that having the default
ListView dividers (the horizontal line between your element views) is causing some graphical glitches for the first load.
If that’s the case for you too, you can disable them in your XML layout by setting: