2

Wanna implement the filling of my ListView with the effect like that: the first item rotates X and fades in, later the second one and so on.

One way to do it is clear - add items one by one to the adapter (just like in that post), while the animations are handled by LayoutTransition object, which I set in advance.

However, I have a strange feeling, like it'd be somewhat a crutch to add items asycnchoniously just in sake of animation effect. Does anybody know how to do it better?

UPD: Some details: I want items to be animated only when the underlying data changes, for instance, the server sends new info and the list updates, just like the old departure boards in airports.

Community
  • 1
  • 1
Dmitry Gryazin
  • 933
  • 1
  • 11
  • 24

3 Answers3

4

Use a LayoutAnimationController....

LayoutAnimationController lac = new LayoutAnimationController(AnimationUtils.loadAnimation(getActivity(), R.anim.table_row_appear), 0.5f); //0.5f == time between appearance of listview items.
listView.setLayoutAnimation(lac);

Whenever you want to run the animation :

listView.startLayoutAnimation();
ElDuderino
  • 3,253
  • 2
  • 21
  • 38
  • 2
    Nice thing, that class computes the delay for every animation, however there is a couple of drawbacks making this solution weak. 1) I don't see a way to use it with android 3.0+ animators framefork (one is welcome for suggestions). Using old animations is a kind of perversion to my mind. 2) You need to manually control the moment when to start animations - it's painful and adds excess complexity to the code. – Dmitry Gryazin Oct 21 '14 at 21:29
1

Finally, I ended up with using the LinearLayout instead of ListView because of the view reusage, that reruns the animation for every view whenever it's showed up again.

But I did it just because I didn't have too many items to show. Another approach, as I guess, is to load animations in adapter, compute delay in accordance with item position and to store the map with the info, wether the view has already been animated in or not.

Dmitry Gryazin
  • 933
  • 1
  • 11
  • 24
0

You can create an animation(transition + fade or any other effect you want) and add the animation to the Layout (view) that you return in "getView"

the animation shall take in consideration the "position" parameter to create the delay when the animation is started.

enjoy

daniel

danysz
  • 580
  • 3
  • 11
  • This solution will cause the animation to play on the list scroll - you get problems with views reusing. – Dmitry Gryazin Oct 21 '14 at 21:38
  • From what I understand he wants to be played while the list is scrolling (maybe I am wrong), and there is no problem with the reuse because you restart the animation with the reuse. "a new item is showing and of course is coming again"..maybe more details in the request will help us to give a better solution. – danysz Oct 22 '14 at 04:45