As RadListView extends RecyclerView it provides the same item animation mechanism. Namely — you can use the setItemAnimator(ItemAnimator) method to change the animator that is used. The item animations are played each time an item is added to the list or when it is removed. You can extend the ItemAnimator class and implement you own animator or use one of those that we have implemented: Fade, Slide and Scale.
You can easily change that DefaultItemAnimator by the setItemAnimator(ItemAnimator). The animators that are implemented are:
Note that this animations will be played when items are added or removed (for example by calling adapter's add or remove methods) and not when the items are loaded to populate the initial list.
Here's how we can add a FadeItemAnimator to a list view instance:
FadeItemAnimator fadeItemAnimator = new FadeItemAnimator();
listView.setItemAnimator(fadeItemAnimator);
FadeItemAnimator fadeItemAnimator = new FadeItemAnimator ();
listView.SetItemAnimator (fadeItemAnimator);
In order to see the effect, you can add a button somewhere and use it to add another item to the list by adapter's add() method.
By default the items will fade from 0
when they appear and fade to 0
when they disappear. You can change this by using FadeItemAnimator's setAlpha(float) method. The alpha value can be between 0
and 1
, where 0
means
full transparency and 1
means no transparency.
Here's how we can add a SlideItemAnimator to a list view instance:
SlideItemAnimator slideItemAnimator = new SlideItemAnimator();
listView.setItemAnimator(slideItemAnimator);
SlideItemAnimator slideItemAnimator = new SlideItemAnimator ();
listView.SetItemAnimator (slideItemAnimator);
In order to see the effect, you can add a button somewhere and use it to add another item to the list by adapter's add() method.
By default the items will slide from and to the right. You can change this by using SlideItemAnimator's setAnimateInDirection(int) and setAnimateOutDirection(int). Here are the constants that you can use: SlideItemAnimator.DIRECTION_LEFT, SlideItemAnimator.DIRECTION_TOP, SlideItemAnimator.DIRECTION_RIGHT, SlideItemAnimator.DIRECTION_BOTTOM.
Here's how we can add a SlideItemAnimator to a list view instance:
ScaleItemAnimator scaleItemAnimator = new ScaleItemAnimator();
listView.setItemAnimator(scaleItemAnimator);
ScaleItemAnimator scaleItemAnimator = new ScaleItemAnimator ();
listView.SetItemAnimator (scaleItemAnimator);
In order to see the effect, you can add a button somewhere and use it to add another item to the list by adapter's add() method.
By default the items will scale from 0.3f
when you add them and to 0.3
when you remove them. The scale will be applied to both dimensions of the item (height and width).
You can change these values by using ScaleItemAnimator's
setScaleX(float) and setScaleY(float) methods. It you set one of the scales to 1.0f
, this means that the item will not scale at all in this dimension.
You can use the ItemAnimatorSet class to combine the animators. Additionally the animators have a setType method that allows you to define whether an animator will be used for animation when an item is added or removed or both. Here's how to include use scale animator when an item is added and slide animator when an item is removed.
ScaleItemAnimator scaleItemAnimator = new ScaleItemAnimator();
scaleItemAnimator.setType(ListViewItemAnimator.ADD);
SlideItemAnimator slideItemAnimator = new SlideItemAnimator();
slideItemAnimator.setType(ListViewItemAnimator.REMOVE);
ItemAnimatorSet itemAnimatorSet = new ItemAnimatorSet();
itemAnimatorSet.addAnimator(scaleItemAnimator);
itemAnimatorSet.addAnimator(slideItemAnimator);
listView.setItemAnimator(itemAnimatorSet);
ScaleItemAnimator scaleItemAnimator = new ScaleItemAnimator();
scaleItemAnimator.Type = ListViewItemAnimator.Add;
SlideItemAnimator slideItemAnimator = new SlideItemAnimator();
slideItemAnimator.Type = ListViewItemAnimator.Remove;
ItemAnimatorSet itemAnimatorSet = new ItemAnimatorSet();
itemAnimatorSet.AddAnimator(scaleItemAnimator);
itemAnimatorSet.AddAnimator(slideItemAnimator);
listView.SetItemAnimator(itemAnimatorSet);