Animate newly added items in ListView

后端 未结 3 1989
梦如初夏
梦如初夏 2020-12-28 08:21

How can I animate newly added items in ListView?

I have a adapter and when I add new items in my list I say adapter.notifyDataSetChan

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-28 09:03

    Adding this kind of animations is harder than I first thought of. There are two ways depending of the kind of animation you are trying to achieve.

    • Using LayoutAnimationController. There is an example in the API demos.

    • Animating each View:

    This is quite a hack but the only way I found to add an animation to ListView's children is the following:

    You can try notifying the adapter the id of the item you are willing to delete and call adapter.notifyDataSetChanged();. This will generate calls to the adapter's getView() method. Inside it you can do something like:

    if ( item.getId() == itemToRemove ) {
     //apply the animation
    }
    

    After the animation finished you can recall adapter.notifyDataSetChanged() to put everything in place.

提交回复
热议问题