Android listview: Animate listview item like Google plus effect

There a few weeks ago when I was working on Android “Cup of News” application, I wanted to replicate the effect “Google Plus” on the various items contained in a listview.

From my point of view, the use of such effects must do this sparingly. Everything depends on the content in each item that makes up your listview.

I have long sought a solution that is adequate but after some research on the web, I came to a rather acceptable solution.

Create a global variable which will be used to store the last item position the listview :

private int lastPosition = -1 ;

Create the first animation file: up_from_bottom.xml :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="@android:anim/decelerate_interpolator">
    <translate
        android:fromXDelta="0%" android:toXDelta="0%"
        android:fromYDelta="100%" android:toYDelta="0%"
        android:duration="400" />
</set>

Create the second animation file: down_from_top.xml :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="@android:anim/decelerate_interpolator">
    <translate
        android:fromXDelta="0%" android:toXDelta="0%"
        android:fromYDelta="-100%" android:toYDelta="0%"
        android:duration="400" />
</set>

And add the following code at the end of your getView(..) method :

Animation animation = AnimationUtils.loadAnimation(getContext(), (position > lastPosition) ? R.anim.up_from_bottomm : R.anim.down_from_top);
rowView.startAnimation(animation);
lastPosition = position;

Sources : #

[1] AnimationUtils | Android Developers http://developer.android.com/reference/android/view/animation/AnimationUtils.html

 
109
Kudos
 
109
Kudos

Now read this

Rounded ImageView with thin border #Android

Here is a little trick to create a rounded ImageView with a thin border. We use this class : I spent a lot of time to search on the web a class which allows to create a rotation effect on each item of an Android listview. Here is a good... Continue →